React version: 16
valueBnever gets logged
Link to code example: https://stackblitz.com/edit/react-hooks-demo-f69yc7?file=App.js
When clicked the "Test App" div
valueB never gets logged.
Not sure what the expected behavior should be, just it seemed strange
valueB was never logged.
After putting some
console.logs and using functional
setState, I can see why
valueB was not logged, because it was overwritten by
setB(null) from previous renders
useEffect return function. Just still this behavior seemed a bit strange to me, so wanted to share to make sure this is not a bug. Is it?
Yeah, that's the behavior in 16. If you check out the behavior in 18 below you can see that it's been updated to batch the updates with a more predictable outcome (automatic batching):
|Issue Title||Created Date||Updated Date|