Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 65x 65x 67x 67x 390x 390x 325x 2988x 1264x | import { useSyncExternalStore } from 'react'
import type { RouteContext } from '@/layers/interfaces'
let current: RouteContext | null = null
const listeners = new Set<() => void>()
export function setRouteContext(ctx: RouteContext | null) {
current = ctx
listeners.forEach((l) => l())
}
function subscribe(fn: () => void) {
listeners.add(fn)
return () => { listeners.delete(fn) }
}
function getSnapshot(): RouteContext | null {
return current
}
export function useRouteContext(): RouteContext | null {
return useSyncExternalStore(subscribe, getSnapshot)
}
|