-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature/BAR-38] zustand 기본 세팅 (#10)
* feat: zustand 추가 * feat: modalStore 작성 * feat: useStoreWithEqualityFn를 사용하는 형태로 변경
- Loading branch information
Showing
3 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |