Friday 12 April 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...