-
|
Hello, I’m new to Zustand and trying to understand how the From the documentation, I see that Here is my current implementation: import { createStore } from 'zustand';
import { persist } from 'zustand/middleware';
const authStore = createStore<AuthStore>()(
persist(
(set, get) => ({
accessToken: get().accessToken ?? null,
refreshToken: get().refreshToken ?? null,
user: get().user ?? null,
}),
{ name: AUTH_STORE_NAME },
),
);The issue is that nothing appears in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The initializer should return the default state. Do not read For example: const authStore = createStore<AuthStore>()(
persist(
(set) => ({
accessToken: null,
refreshToken: null,
user: null,
setTokens: ({ accessToken, refreshToken }) =>
set({ accessToken, refreshToken }),
setUser: (user) => set({ user }),
logout: () =>
set({ accessToken: null, refreshToken: null, user: null }),
}),
{
name: AUTH_STORE_NAME,
partialize: ({ accessToken, refreshToken, user }) => ({
accessToken,
refreshToken,
user,
}),
},
),
)
If this runs in an SSR environment, remember that |
Beta Was this translation helpful? Give feedback.
The initializer should return the default state. Do not read
get()there to initialize the same fields, because hydration is handled bypersistafter the store is created.For example: