atom not resetting to initial state instantly if provider is not unmounted #2623
Unanswered
RaulCote
asked this question in
Bug report
Replies: 1 comment 3 replies
-
Yes, it's by design. Think of it as a subscribeable I think you can reset the value with onUnmount. const anAtom = atom(0)
anAtom.onMount = (set) => {
const onUnmount = () => {
set(0)
}
return onUnmount
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
First congratulations for all the amazing work you contribute to the front end state management world.
I have a question that I can't seem to solve, I'm testing Jotai as a way to bind Rxjs with React and I have detected that given a Provider we don't unmount, but all listeners to an atom are unmounted, and then we bring them back, the reset to the initial state can get delayed depending on the operations we are making.
As an example the code below, if both counters are hidden, and then I set to visible one of them, it keeps showing the last value (imagine that I hidden both counters at the second 20, so I unmount both components, wait two seconds, mount one again by setting the visibility to true, and 20 is still in there for a second until it rolls back to 1).
Am I missing something or is it a bug?
It seems like the provider is still storing the last value, it doesn't clear it even if there are no one listening to it.
Beta Was this translation helpful? Give feedback.
All reactions