You get a bonus - 1 coin for daily activity. Now you have 1 coin

Why shouldn't we update state directly in REACT?

Practice



If you try to update state directly, the component will not re-render.

// Wrong 
this.state.message = 'Hello world'
 

Instead, use the

setState()
method. It schedules an update to the component's state object. When state changes, the component responds by re-rendering.
// Correct 
this . setState ({message :  ' Hello World ' })

Note: You can assign the state object directly either in the constructor or by using the class field declaration syntax of the latest version of JavaScript.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone