Skip to content

Commit

Permalink
refactor: zustand-persist 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
2NNS-V committed Sep 11, 2024
1 parent 2c6413c commit d39e121
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { create } from "zustand";

import { persist } from "zustand/middleware";

type UserProps = {
name: string;
department: string;
Expand All @@ -10,9 +12,17 @@ type UserAction = {
setDepartment: (department: UserProps["department"]) => void;
};

export const useUserInfo = create<UserProps & UserAction>()((set) => ({
name: "",
department: "",
setName: (name) => set(() => ({ name: name })),
setDepartment: (department) => set(() => ({ department: department })),
}));
export const useUserInfo = create<UserProps & UserAction>()(
persist(
(set) => ({
name: "",
department: "",
setName: (name) => set(() => ({ name: name })),
setDepartment: (department) => set(() => ({ department: department })),
}),
{
name: "user-storage",
getStorage: () => localStorage,
},
),
);

0 comments on commit d39e121

Please sign in to comment.