How to reset a store to its initial value? #138
Answered
by
ai
AjaxSolutions
asked this question in
Q&A
-
I'm new to Nano Stores,. I'd like to use it on a complex modal. When the modal closes, how would I reset all stores used by the modal to their respective initial values? |
Beta Was this translation helpful? Give feedback.
Answered by
ai
Jan 16, 2023
Replies: 1 comment
-
import { onMount } from 'nanostores'
onMount(store, () => {
// first mount
return () => {
// unmount of latest subscriber
}
}) Add it to all stores and reset their value. When you will close popup and there are not any other listeners for store’s data, this callback will be executed and reset the data in stores. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AjaxSolutions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
onMount(store, cb)
adds callback on the first mount and on unmount of latest subscriber.Add it to all stores and reset their value. When you will close popup and there are not any other listeners for store’s data, this callback will be executed and reset the data in stores.