TimestampInfoProvider.tsx23 lines · main
| 1 | 'use client' |
| 2 | |
| 3 | import { createContext, useContext, useMemo, type ReactNode } from 'react' |
| 4 | |
| 5 | interface TimestampInfoContextValue { |
| 6 | /** IANA timezone applied to TimestampInfo when no `timezone` prop is set. */ |
| 7 | timezone?: string |
| 8 | } |
| 9 | |
| 10 | const TimestampInfoContext = createContext<TimestampInfoContextValue>({}) |
| 11 | |
| 12 | export const TimestampInfoProvider = ({ |
| 13 | timezone, |
| 14 | children, |
| 15 | }: { |
| 16 | timezone?: string |
| 17 | children: ReactNode |
| 18 | }) => { |
| 19 | const value = useMemo(() => ({ timezone }), [timezone]) |
| 20 | return <TimestampInfoContext.Provider value={value}>{children}</TimestampInfoContext.Provider> |
| 21 | } |
| 22 | |
| 23 | export const useTimestampInfoContext = () => useContext(TimestampInfoContext) |