Refactor RealmContext
to use React Router v6 (#4182)
This commit is contained in:
parent
23e1aa54a7
commit
66cf2ad368
1 changed files with 8 additions and 8 deletions
|
@ -1,10 +1,8 @@
|
||||||
import { FunctionComponent, useEffect, useMemo } from "react";
|
import { FunctionComponent, useEffect, useMemo } from "react";
|
||||||
import { useRouteMatch } from "react-router-dom";
|
import { useMatch } from "react-router-dom-v5-compat";
|
||||||
|
|
||||||
import { RecentUsed } from "../../components/realm-selector/recent-used";
|
import { RecentUsed } from "../../components/realm-selector/recent-used";
|
||||||
import {
|
import { DashboardRouteWithRealm } from "../../dashboard/routes/Dashboard";
|
||||||
DashboardParams,
|
|
||||||
DashboardRouteWithRealm,
|
|
||||||
} from "../../dashboard/routes/Dashboard";
|
|
||||||
import environment from "../../environment";
|
import environment from "../../environment";
|
||||||
import { createNamedContext } from "../../utils/createNamedContext";
|
import { createNamedContext } from "../../utils/createNamedContext";
|
||||||
import useRequiredContext from "../../utils/useRequiredContext";
|
import useRequiredContext from "../../utils/useRequiredContext";
|
||||||
|
@ -22,9 +20,11 @@ export const RealmContext = createNamedContext<RealmContextType | undefined>(
|
||||||
export const RealmContextProvider: FunctionComponent = ({ children }) => {
|
export const RealmContextProvider: FunctionComponent = ({ children }) => {
|
||||||
const { adminClient } = useAdminClient();
|
const { adminClient } = useAdminClient();
|
||||||
const recentUsed = useMemo(() => new RecentUsed(), []);
|
const recentUsed = useMemo(() => new RecentUsed(), []);
|
||||||
const routeMatch = useRouteMatch<DashboardParams>(
|
const routeMatch = useMatch({
|
||||||
DashboardRouteWithRealm.path
|
path: DashboardRouteWithRealm.path,
|
||||||
);
|
end: false,
|
||||||
|
});
|
||||||
|
|
||||||
const realmParam = routeMatch?.params.realm;
|
const realmParam = routeMatch?.params.realm;
|
||||||
const realm = useMemo(
|
const realm = useMemo(
|
||||||
() => realmParam ?? environment.loginRealm,
|
() => realmParam ?? environment.loginRealm,
|
||||||
|
|
Loading…
Reference in a new issue