React Hooks useState+useEffect+event gives stale state
I’m trying to use an event emitter with React useEffect
and useState
, but it always gets the initial state instead of the updated state. It works if I call the event handler directly, even with a setTimeout
.