Tuesday, March 26, 2019

javascript - TypeError: Cannont Read Property `State` of Undefined




Getting the error :




TypeError: Cannot read property 'state' of undefined




I face this error when i am going to get my input state value by event onSubmit() .



onFormSubmit(event){

event.preventDefault();
console.log(this.state.term);
}

Answer



Use arrow function instead so:



Change



onFormSubmit(event){

event.preventDefault();
console.log(this.state.term);
}


To



onFormSubmit= (event)=>{
event.preventDefault();
console.log(this.state.term);

}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...