Answer the question
In order to leave comments, you need to log in
How to call a dispatcher with a value?
const todos = [1,.....10000]
render() {
return todos.map(item => (
<div key={item.id} onClick={()=>this.props.toggleTodo(item.id)} />
));
}
}
<Todo toggle = {this.props.toggleTodo} data={item}>
Answer the question
In order to leave comments, you need to log in
To solve this problem, you can use the data attribute:
handleTodoClick = e => {
const { id } = e.target.dataset;
this.props.toggleTodo(id);
};
render() {
return todos.map(item => (
<div key={item.id} data-id={item.id} onClick={this.handleTodoClick} />
));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question