Skip to content

How to reset a store to its initial value? #138

Answered by ai
AjaxSolutions asked this question in Q&A
Discussion options

You must be logged in to vote

onMount(store, cb) adds callback on the first mount and on unmount of latest subscriber.

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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AjaxSolutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants