You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wasn't sure exactly how to explain this - it was an issue that came up as I was trying to implement drag and drop and had quite a lot of event handlers all over the place.
I've done my best to make a minimal reproduction, hope it's not too vague!
The component below sets up a timer which increments a counter.
The raw react version increments the number on every tick, it calls the version of setNum that takes a function. The hx version only increments once, but doesn't continue to increment, I think because it is holding a reference to the initial state.
I had encountered this before and thought I was using it wrong. Your example was helpful in that it illustrates the difference between useState and <-state.
I believe the problem is that the implementation of ISwap has an implicit dependency on the current value in the Atomified instance. When your initial closure is created with useEffect, it captures that initial value in the atom instance and never gets the updated value.
I wasn't sure exactly how to explain this - it was an issue that came up as I was trying to implement drag and drop and had quite a lot of event handlers all over the place.
I've done my best to make a minimal reproduction, hope it's not too vague!
The component below sets up a timer which increments a counter.
The raw react version increments the number on every tick, it calls the version of
setNum
that takes a function. The hx version only increments once, but doesn't continue to increment, I think because it is holding a reference to the initial state.The text was updated successfully, but these errors were encountered: