Answer the question
In order to leave comments, you need to log in
React. What is the correct way to bind the event to the elements displayed in the loop?
When displaying elements in a component through a loop, you need to hang a mouseover event on each of them. But with this implementation, the event fires on all elements at once.
Hover function:
SomeFunction () {
this.setState=({
hover: !this.state.hover
})
}
const arr = data.map((item, id) => {
<div key={id} onMouseEnter={() => this.SomeFunction()}>
<span className='someClass'>{item.name}</span>
<SomeComponent hover={this.state.hover} data={item.data}/>
</div>
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question