Skip to content

Scoped store

Scoped store

If your app is SSR or for example you just want to have the same store shape but keep different values for different routes you can use scoped store

It returns:

  • StoreProvider - Provider that passes scoped store down to the React’s tree
  • withStore - HOC that passes scoped store down to the React’s tree
  • useScopedStore - React hook used to access scoped store (actions, effect, etc.)
  • useStore - Regular useStore hook but with the scoped store
  • useStoreEffect - Regular useStoreEffect hook but with the scoped store
import { createScopedStore } from 'stan-js'
export const { StoreProvider, useScopedStore, withStore, useStore, useStoreEffect } = createScopedStore({
count: 0,
})

Examples