Files
sgw-owner-app/state/use-fish.ts
2025-11-28 16:59:57 +07:00

27 lines
733 B
TypeScript

import { queryFish } from "@/controller/FishController";
import { create } from "zustand";
type Fish = {
fishSpecies: Model.FishSpeciesResponse[] | null;
getFishSpecies: () => Promise<void>;
error: string | null;
loading?: boolean;
};
export const useFishes = create<Fish>((set) => ({
fishSpecies: null,
getFishSpecies: async () => {
try {
const response = await queryFish();
console.log("Fish fetching API: ", response.data.length);
set({ fishSpecies: response.data, loading: false });
} catch (error) {
console.error("Error when fetch fish: ", error);
set({ error: "Failed to fetch fish data", loading: false });
set({ fishSpecies: null });
}
},
error: null,
}));