What happens if you use setState() in the constructor? in REACT

Practice



When you use
setState()
, then, apart from assigning to the state object, React also re-renders the component and all of its children. You will get an error similar to this: only a mounted or mounting component can be updated. So we need to use
this.state
to initialise variables inside the constructor.

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