Skip to content
Advertisement

TypeError: Cannot read property ‘handleChange’ of undefined

I am trying to build a todo list app with React. Getting the error “Cannot read property of handleChange undefined”. Below is the code i am working on. Moreover, todosData is an array of objects having id, text and completed(boolean – true/false) as properties.

JavaScript

The content.js is as follows,

JavaScript

And finally the array todosData,

JavaScript

Advertisement

Answer

Because this is function-scoped, except for arrow-functions.

JavaScript

Alternative, if you have to use function.

JavaScript

See also How to access the correct `this` inside a callback?

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement