React Flashcards
1
Q
Name three basic rules for working with React class objects’ states.
A
- Never change this.state directly.
Always use this.setState(). The only place where you can change this.state is constructor of the component. - Remember that state update might be asynchronous.
To synchronize them, pass a function into setState(); This function should accept two arguments: the initial state and the updated props. It should return the new state object. - State updates are merged.