replace redux with zustand
This commit is contained in:
25
src/store/kvv.ts
Normal file
25
src/store/kvv.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { create } from "zustand";
|
||||
import { fetchKvvDepartures } from "@/api/kvv";
|
||||
import type { DepartureType } from "@/types/departureType";
|
||||
import { devtools } from "zustand/middleware";
|
||||
|
||||
const useKVVStore = create(
|
||||
devtools((set) => ({
|
||||
pStreet: [] as DepartureType[],
|
||||
hStreet: [] as DepartureType[],
|
||||
fetch: async () => {
|
||||
const hStreetStopId = 7000044;
|
||||
const pStreetStopId = 7000045;
|
||||
const hStreetData = await fetchKvvDepartures(hStreetStopId);
|
||||
const pStreetData = await fetchKvvDepartures(pStreetStopId);
|
||||
const hStreetJson = await hStreetData.json();
|
||||
const pStreetJson = await pStreetData.json();
|
||||
set({
|
||||
hStreet: hStreetJson as DepartureType[],
|
||||
pStreet: pStreetJson as DepartureType[],
|
||||
});
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
export { useKVVStore };
|
||||
Reference in New Issue
Block a user