Sometimes, we want to fix TypeError: Cannot read property ‘props’ of undefined with React.
In this article, we’ll look at how to fix TypeError: Cannot read property ‘props’ of undefined with React.
How to fix TypeError: Cannot read property ‘props’ of undefined with React?
To fix TypeError: Cannot read property ‘props’ of undefined with React, we should make sure the value of this
is correct.
For instance, we write
class Parent extends React.Component {
state = {
//...
};
onDelete = () => {
//...
};
render() {
return <Child onDelete={this.onDelete} />;
}
}
to add the onDelete
function which has the value of this
set to the Parent
component instance since it’s an arrow function.
Conclusion
To fix TypeError: Cannot read property ‘props’ of undefined with React, we should make sure the value of this
is correct.