replace redux with zustand
This commit is contained in:
26
src/store/flatastic.ts
Normal file
26
src/store/flatastic.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { create } from "zustand";
|
||||
import Flatastic from "@/api/flatastic";
|
||||
import type { FlatasticChore } from "@/types/flatasticChore";
|
||||
|
||||
interface FlatasticStore {
|
||||
chores: FlatasticChore[];
|
||||
fetch: () => Promise<void>;
|
||||
}
|
||||
|
||||
const useFlatasticStore = create<FlatasticStore>(
|
||||
(set: (state: Partial<FlatasticStore>) => void) => ({
|
||||
chores: [],
|
||||
fetch: async () => {
|
||||
if (!import.meta.env.VITE_FLATTASTIC_API_KEY) {
|
||||
throw new Error("Flatastic API Key is not set");
|
||||
}
|
||||
const flatastic = new Flatastic(import.meta.env.VITE_FLATTASTIC_API_KEY);
|
||||
const data = await flatastic.getTaskList();
|
||||
|
||||
console.log("Flatastic chores fetched:", data);
|
||||
set({ chores: data as FlatasticChore[] });
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
export { useFlatasticStore };
|
||||
Reference in New Issue
Block a user