init State Mangement and add del function

This commit is contained in:
Patryk
2025-04-22 18:35:39 +02:00
parent 5e44b30a49
commit 8f5b151d87
8 changed files with 252 additions and 185 deletions

23
store.js Normal file
View File

@@ -0,0 +1,23 @@
import { create } from 'zustand';
import { locations as initialLocations } from '@/data/locations';
console.log('Initial locations:', initialLocations);
const useLocationStore = create((set) => ({
locations: initialLocations,
addLocation: (newLocation) =>
set((state) => ({
locations: [newLocation, ...state.locations],
})),
updateLocation: (id, updatedData) =>
set((state) => ({
locations: state.locations.map((loc) =>
loc.id == id ? { ...loc, ...updatedData } : loc
),
})),
deleteLocation: (id) =>
set((state) => ({
locations: state.locations.filter((loc) => loc.id != id),
})),
}));
export default useLocationStore;