Answer the question
In order to leave comments, you need to log in
Why doesn't it let you hang a callback on the react component?
I have such an application with a card where I add tasks.
https://codepen.io/Gleblq/pen/PoNjKZW
The idea is that when you click on the "delete" button (this is when we have already added tasks to the card), a callback to the deleteTaskHandler () function, which is located in card component. But when I try to add tasks to the card, an error occurs ('Uncaught TypeError: Cannot read property 'deleteTaskHandler' of undefined'). I don't understand why it doesn't let me attach a callback function to this component. If I display the Task Components separately, not through the .map function , then everything works correctly.
Please share your ideas)
Answer the question
In order to leave comments, you need to log in
taskList.map(function(item) {
return (
<Task data_text={item.text} key={item.id} delete={this.deleteTaskHandler}/>
)
})
this.deleteTaskHandler
- this is not a component method.onCLick={this.props.deleteTaskHandler()}
deleteTaskHandler
, if you pass to a component instance delete
? Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question