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
constuseCounterStore=<U,>(
key: string,
selector: (state: CounterStore) =>U,initState: InitState)=>{conststores=useContext(CounterStoresContext)if(stores===undefined){thrownewError('useCounterStore must be used within CounterStoresProvider')}constgetOrCreateCounterStoreByKey=useCallback((key: string)=>createCounterStoreFactory(stores!,initState)(key),[stores],)returnuseStore(getOrCreateCounterStoreByKey(key),selector)}``````jsconstcreateCounterStoreFactory=(counterStores: Map<string,ReturnType<typeofcreateCounterStore>>,initState: InitState)=>{return(counterStoreKey: string)=>{if(!counterStores.has(counterStoreKey)){counterStores.set(counterStoreKey,createCounterStore(initState))}returncounterStores.get(counterStoreKey)!}}```
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm following this guide to create multiple dynamic scoped vallina store: https://zustand.docs.pmnd.rs/hooks/use-store#using-dynamic-scoped-(non-global)-vanilla-stores-in-react
But I wonder how to init these store with state from props like: https://zustand.docs.pmnd.rs/guides/initialize-state-with-props
I tried to add prop into hook but it doesn't work
Beta Was this translation helpful? Give feedback.
All reactions