From 983b7977ce60328a7ec696049a1794a34e38dd7c Mon Sep 17 00:00:00 2001 From: hojin Date: Wed, 15 May 2024 20:00:48 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20zustand=20=EC=98=88=EC=8B=9C=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=90=EC=84=9C=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EB=82=98=EC=84=9C=20=EA=B7=B8=EB=83=A5=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/testPopular.ts | 14 ++++++++ src/store/example.store.ts | 70 -------------------------------------- 2 files changed, 14 insertions(+), 70 deletions(-) create mode 100644 src/models/testPopular.ts delete mode 100644 src/store/example.store.ts diff --git a/src/models/testPopular.ts b/src/models/testPopular.ts new file mode 100644 index 0000000..6ec4717 --- /dev/null +++ b/src/models/testPopular.ts @@ -0,0 +1,14 @@ +export interface testPopularType { + status: string; + errorCode: string | null; + data: testPopularData[]; + message: string | null; +} + +export interface testPopularData { + content: string; + tag: string[]; + viewCount: number; + replyCount: number; + category?: string; +} diff --git a/src/store/example.store.ts b/src/store/example.store.ts deleted file mode 100644 index d42537c..0000000 --- a/src/store/example.store.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { create } from 'zustand'; -import { devtools, persist } from 'zustand/middleware'; - -//기본 사용법 타입 에러는 일단 무시 - -let todoStore = (set) => ({ - todos: [], - addTodo: (payload) => - set((state) => ({ - todos: [ - ...state.todos, - { - text: payload.text, - isCompleted: payload.isCompleted - } - ] - })), - - deleteTodo: (payload) => - set((state) => ({ - todos: state.todo.filter((todo) => todo.id !== payload.id) - })), - - completeTodo: (payload) => - set((state) => ({ - todos: state.todos.map((todo) -> { - if(todo.id === payload.id){ - return { - ...todo, - isComplete : true - } - } - }) - })) -}); - -// redux devtools처럼 chrome 확장자 앱 사용해서 사용가능 -todoStore = devtools(todoStore); - -// persist 새로고침시 데이터 유지 -todoStore = persist(todoStore, { - name: 'userStore' -}); - -//store 완성 다른 작업 필요없이 갖다쓰면됨 -export const useTodoStore = create(todoStore); - -// 예시 -const {addTodo, deleteTodo ,completeTodo} = useTodoStore() - -const handleAddTodo = () => { - addTodo{ - text : 'Add Todo', - isCompleted : false, - id: 1 - } -} - -const handleDeleteTodo = () => { - deleteTodo{ - id : 1 - } -} - -const handleCompleteTodo = () => { - completeTodo{ - text : 'Add Todo', - isCompleted : false, - id: 1 - }