mirror of
https://github.com/ferdzo/iotDashboard.git
synced 2026-04-05 01:06:24 +00:00
41 lines
974 B
TypeScript
41 lines
974 B
TypeScript
import { createContext, useContext, useState, type ReactNode } from 'react'
|
|
|
|
interface WellnessState {
|
|
healthDeviceId: string | null
|
|
city: string
|
|
setHealthDeviceId: (id: string | null) => void
|
|
setCity: (city: string) => void
|
|
}
|
|
|
|
const WellnessStateContext = createContext<WellnessState | undefined>(undefined)
|
|
|
|
export function WellnessStateProvider({ children }: { children: ReactNode }) {
|
|
const [healthDeviceId, setHealthDeviceId] = useState<string | null>(null)
|
|
const [city, setCity] = useState<string>('Skopje')
|
|
|
|
return (
|
|
<WellnessStateContext.Provider
|
|
value={{
|
|
healthDeviceId,
|
|
city,
|
|
setHealthDeviceId,
|
|
setCity,
|
|
}}
|
|
>
|
|
{children}
|
|
</WellnessStateContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useWellnessState() {
|
|
const context = useContext(WellnessStateContext)
|
|
if (context === undefined) {
|
|
throw new Error('useWellnessState must be used within WellnessStateProvider')
|
|
}
|
|
return context
|
|
}
|
|
|
|
|
|
|
|
|