Skip to content

Commit

Permalink
[Feature/BAR-38] zustand 기본 세팅 (#10)
Browse files Browse the repository at this point in the history
* feat: zustand 추가

* feat: modalStore 작성

* feat: useStoreWithEqualityFn를 사용하는 형태로 변경
  • Loading branch information
miro-ring authored Dec 20, 2023
1 parent 8ec5ab7 commit 6c8e150
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"clsx": "^2.0.0",
"next": "14.0.3",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"zustand": "^4.4.7"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.6.4",
Expand Down
34 changes: 31 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/components/Modal/stores/modalStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createStore } from 'zustand';
import { useStoreWithEqualityFn as useStore } from 'zustand/traditional';

const initialModalData = {
title: '',
firstButtonText: '',
};

interface ModalData {
title: string;
description?: string;
firstButtonText: string;
secondButtonText?: string;
}

interface State {
modalData: ModalData;
}

interface Action {
openModal: (modalData: ModalData) => void;
}

export const modalStore = createStore<State & Action>((set) => ({
modalData: initialModalData,
openModal: (modalData) => set({ modalData }),
}));

export const useModalStore = <T>(
selector: (state: State & Action) => T,
equals?: (a: T, b: T) => boolean,
) => useStore(modalStore, selector, equals);

0 comments on commit 6c8e150

Please sign in to comment.