26 lines
754 B
TypeScript
26 lines
754 B
TypeScript
'use client'
|
|
|
|
import { createContext, useContext } from 'react'
|
|
import { EMPTY_EVENT, type PublicEvent } from '@/lib/event-types'
|
|
|
|
interface EventContextValue {
|
|
event: PublicEvent
|
|
registrationEnabled: boolean
|
|
}
|
|
|
|
const EventContext = createContext<EventContextValue>({ event: EMPTY_EVENT, registrationEnabled: false })
|
|
|
|
export function EventProvider({
|
|
event,
|
|
registrationEnabled,
|
|
children,
|
|
}: EventContextValue & { children: React.ReactNode }) {
|
|
return <EventContext.Provider value={{ event, registrationEnabled }}>{children}</EventContext.Provider>
|
|
}
|
|
|
|
// Client components read the current edition and its races from here. The root layout
|
|
// fetches them once per page render.
|
|
export function useEvent() {
|
|
return useContext(EventContext)
|
|
}
|