@etsoo/toolpad
Version:
Dashboard framework extention based on Toolpad Core
30 lines (29 loc) • 1.09 kB
JavaScript
"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import * as React from "react";
import { useSearchParams, useLocation, useNavigate } from "react-router-dom";
import { AppProvider as AppProviderComponent } from "../AppProvider/AppProviderComponent";
/**
* @ignore - internal component.
*/
function AppProvider(props) {
const { pathname } = useLocation();
const [searchParams] = useSearchParams();
const navigate = useNavigate();
const navigateImpl = React.useCallback((url, { history = "auto" } = {}) => {
if (history === "auto" || history === "push") {
return navigate(url);
}
if (history === "replace") {
return navigate(url, { replace: true });
}
throw new Error(`Invalid history option: ${history}`);
}, [navigate]);
const routerImpl = React.useMemo(() => ({
pathname,
searchParams,
navigate: navigateImpl
}), [pathname, searchParams, navigateImpl]);
return _jsx(AppProviderComponent, { router: routerImpl, ...props });
}
export { AppProvider };