Skip to content
Discussion options

You must be logged in to vote

The initializer should return the default state. Do not read get() there to initialize the same fields, because hydration is handled by persist after the store is created.

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,

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Bubuioc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants