pmndrs / zustand

🐻 Bear necessities for state management in React

Home Page:https://zustand-demo.pmnd.rs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resetting Multiple Stores Example Doesn't Work with the Currying Required Elsewhere for Typescript Support

TiKevin83 opened this issue · comments

Something is wrong with the documentation on how to reset all stores with respect to the currying needed for Typescript support:

https://docs.pmnd.rs/zustand/guides/how-to-reset-state

As is my existing code that has the extra currying () doesn't create the store properly using the example create() function. I was able to get around it by rewriting my code to not curry in my stores and to replicate the currying inside the custom create, which is actually probably better in my case because now I'm enforcing that my stores use persist and that they implement a reset function, but probably loses the extensibility desired by the example:

export const createPersistingStore = <T extends ResettableState>(
  f: StateCreator<T, [], [['zustand/persist', unknown]]>
) => {
  const store = _create<T>()(f);
  resetters.push(() => {
    store.getState().reset();
  });
  return store;
};