TimestampInfoProvider.tsx23 lines · main
1'use client'
2
3import { createContext, useContext, useMemo, type ReactNode } from 'react'
4
5interface TimestampInfoContextValue {
6 /** IANA timezone applied to TimestampInfo when no `timezone` prop is set. */
7 timezone?: string
8}
9
10const TimestampInfoContext = createContext<TimestampInfoContextValue>({})
11
12export 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
23export const useTimestampInfoContext = () => useContext(TimestampInfoContext)