init State Mangement and add del function
This commit is contained in:
23
store.js
Normal file
23
store.js
Normal 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;
|
||||
Reference in New Issue
Block a user