Sun, Nov 12, 2023
1 note this week
- Nov 8, 2023
React’s
setStateis asynchronous: readthis.stateright after calling it and you may get the old value. To act on the new state, pass a callback, or usecomponentDidUpdate(which also fires on prop changes). From React gotchas.this.setState({ name: 'Jon' }, () => { // runs after the state update and re-render });