Javascript React Uncaught Typeerror Cannot

[Solved] Javascript React Uncaught Typeerror Cannot | Actionscript - Code Explorer | yomemimo.com
Question : TypeError: Cannot read property 'setState' of undefined

Answered by : kshitij

class Counter extends React.Component { constructor(props) { super(props); this.state = { count : 1 }; this.delta = this.delta.bind(this);	} delta() { this.setState({ count : this.state.count++ }); } render() { return ( <div> <h1>{this.state.count}</h1> <button onClick={this.delta}>+</button> </div> ); }
}

Source : | Last Update : Tue, 06 Apr 21

Question : Cannot read property 'setState' of undefined

Answered by : hjmcoder

// way #1 - recommended
// puting .bind(this) after using the reference	<input onChange={this.onInputChange.bind(this)} placeholder="First Name" />
// way #2
// adding this line for each method you use constructor(){	this.onInputChange = this.onInputChange.bind(this) } 

Source : | Last Update : Thu, 11 Mar 21

Answers related to javascript react uncaught typeerror cannot read property 39 setstate39 of undefined

Code Explorer Popular Question For Actionscript