In this post, we will explore How To Fix - "This is Undefined" Inside a Component Function in Vue.js or React.js. Error Log
s
this is undefined
This is Undefined
React: 'this.state' is undefined
cannot read props of undefined
Before we proceed, let's do some primitive sanity checks.
npm info react-router-dom version
window.React.version
import React from 'react';
console.log(React.version);
func = () => { ... }
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// This binding is necessary to make \`this\` work in the callback
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState(prevState => ({
isToggleOn: !prevState.isToggleOn
}));
}
render() {
return (
<button onClick={this.handleClick}>
{this.state.isToggleOn ? 'ON' : 'OFF'}
</button>
);
}
}
props undefined react functional component ,this is undefined react function component ,this in functional component ,react class component function is not defined ,why this is undefined in event handler ,event is undefined react ,function is not defined react ,this is undefined in componentdidmount ,This is Undefined ,React: 'this.state' is undefined ,cannot read props of undefined
props undefined react functional component ,this in functional component ,react class component function is not defined ,why this is undefined in event handler ,function is not defined react ,React: 'this.state' is undefined ,cannot read props of undefined ,this is undefined ,this is undefined react ,this is undefined in function javascript ,this is undefined in angular ,this is undefined typescript ,this is undefined in arrow function ,this is undefined inside foreach ,this is undefined in vue js ,this is undefined inside function , ,this is undefined react function component ,event is undefined react ,typeerror event is undefined react ,onclick undefined react ,react onchange this undefined ,this.state is undefined ,this is undefined in componentdidmount ,this in react ,typeerror this is undefined