0

Why it is need to bind the this keyword in react js.

class Hello extends React.Component { constructor(){ super(); this.state = { message: "my friend (from state)!" }; this.updateMessage = this.updateMessage.bind(this); } updateMessage() { this.setState({ message: "my friend (from changed state)!" }); } render() { return <h1>Hello {this.state.message}!</h1>; } }

21st Jan 2021, 3:05 PM
Aman Kumar
Aman Kumar - avatar
1 Antwort