@tanstack/react-router
Version:
Modern and scalable routing for React applications
24 lines (23 loc) • 789 B
JavaScript
import { routerContext } from "./routerContext.js";
import * as React$1 from "react";
//#region src/useRouter.tsx
/**
* Access the current TanStack Router instance from React context.
* Must be used within a `RouterProvider`.
*
* Options:
* - `warn`: Log a warning if no router context is found (default: true).
*
* @returns The registered router instance.
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
*/
function useRouter(opts) {
const value = React$1.useContext(routerContext);
if (process.env.NODE_ENV !== "production") {
if ((opts?.warn ?? true) && !value) console.warn("Warning: useRouter must be used inside a <RouterProvider> component!");
}
return value;
}
//#endregion
export { useRouter };
//# sourceMappingURL=useRouter.js.map