Replies: 2 comments 5 replies
-
In general, I'd prefer disabling the middleware entirely. import { create } from 'zustand'
import { persist, createJSONStorage } from 'zustand/middleware'
export const useBearStore = create(
(enabled ? persist : (fn) => fn)(
(set, get) => ({
bears: 0,
addABear: () => set({ bears: get().bears + 1 }),
}),
{
name: 'food-storage',
storage: createJSONStorage(() => sessionStorage),
},
),
) But, it might be tricky and typing would be hard. |
Beta Was this translation helpful? Give feedback.
5 replies
-
RFC:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The title says it all - will add an example
My use case is more complex than this one, I use
createStore
to create the store within a provider, receiving so different initialisation option (and the flag enabled would be one of this) so allowing me to have the same store working in two different modes in different pages.Beta Was this translation helpful? Give feedback.
All reactions