Refine location handling with Zustand store
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { create } from 'zustand'
|
||||
|
||||
import type { Point } from '@/types/api'
|
||||
|
||||
type Nullable<T> = T | null
|
||||
|
||||
interface AppState {
|
||||
userLocation: Nullable<Point>
|
||||
locationError: Nullable<string>
|
||||
isRequestingLocation: boolean
|
||||
setUserLocation: (location: Nullable<Point>) => void
|
||||
setLocationError: (error: Nullable<string>) => void
|
||||
setIsRequestingLocation: (isRequesting: boolean) => void
|
||||
}
|
||||
|
||||
export const useAppStore = create<AppState>((set) => ({
|
||||
userLocation: null,
|
||||
locationError: null,
|
||||
isRequestingLocation: false,
|
||||
setUserLocation: (userLocation) => set({ userLocation }),
|
||||
setLocationError: (locationError) => set({ locationError }),
|
||||
setIsRequestingLocation: (isRequestingLocation) => set({ isRequestingLocation }),
|
||||
}))
|
||||
Reference in New Issue
Block a user