Question

What's the only place where a React component's this.state can be assigned?

#react

Answer

The only place where this.state can be assigned is the component's constructor.

To set or modify a component's state from anywhere else, setState() must be used, otherwise the change will not trigger a re-rendering of the component.

https://reactjs.org/docs/state-and-lifecycle.html#do-not-modify-state-directly

Learn

Author

xavi

Reviews
Last
next

Students 1