UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

28 lines (23 loc) 566 B
import {useContext} from 'react' import {RouterContext} from './RouterContext' import {type RouterContextValue} from './types' /** * Returns the router context value. * @public * * @returns The router context value. * {@link RouterContextValue} * @throws An error if the router context value is missing. * * @example * ```tsx * const router = useRouter() * ``` */ export function useRouter(): RouterContextValue { const router = useContext(RouterContext) if (!router) { throw new Error('Router: missing context value') } return router }