two setState calls, only the second one sticks in React 18
React 18.3. Component has: const [count, setCount] = useState(0) and const inc = () => { setCount(count + 1); setCount(count + 1) }. Clicking once gives me 1, not 2. I thought React 18 batches but I also thought functional updates were the fix. I tried setCount(c => c + 1) twice and that gave 2. Why does the first version not work but the second does? Trying to understand before I refactor a bunch of code.
4 replies