3 ms·
setName() vs name= are just syntax. None of those have anything to do with how state changes. If you have control over the compiler (which they do) there's no r
by remram 2y ago
setName() vs name= are just syntax. None of those have anything to do with how state changes. If you have control over the compiler (which they do) there's no reason it can't do the right thing (case in point, svelte).
- phailhaus 2y agoThis is not true at all. `setName` queues up a state change for the next render cycle, and has no effect on the current render. You cannot actually edit state directly, so that multiple handlers will all read the same state value regardless of state changes queued up for the next render. const [state, setState] = useState(0) const func = () => { console.log(state) // 0 setState(40) console.log(state) // 0 }