Files
o2o-weather/frontend/src/b/regionContext.ts
T

17 lines
693 B
TypeScript

import { createContext, use } from 'react'
import type { RegionData } from '../api/client/types.gen'
export type LocateStatus = 'idle' | 'locating' | 'denied' | 'error'
export type RegionApi = { region: RegionData; setRegion: (r: RegionData) => void; locate: (onFound?: () => void) => void; locateStatus: LocateStatus }
export const DEFAULT_REGION: RegionData = { code: '1144000000', name: '서울 마포구', short_name: '마포구', lat: 37.56071, lon: 126.91053 }
export const RegionContext = createContext<RegionApi | null>(null)
export function useRegion() {
const ctx = use(RegionContext)
if (!ctx) throw new Error('useRegion must be used inside RegionProvider')
return ctx
}