From 66cf2ad3680501b4e5108668a0c6bfdebb2e422e Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Fri, 13 Jan 2023 16:10:29 +0100 Subject: [PATCH] Refactor `RealmContext` to use React Router v6 (#4182) --- .../src/context/realm-context/RealmContext.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/admin-ui/src/context/realm-context/RealmContext.tsx b/apps/admin-ui/src/context/realm-context/RealmContext.tsx index e85db5ec97..f9308ee5f0 100644 --- a/apps/admin-ui/src/context/realm-context/RealmContext.tsx +++ b/apps/admin-ui/src/context/realm-context/RealmContext.tsx @@ -1,10 +1,8 @@ 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 { - DashboardParams, - DashboardRouteWithRealm, -} from "../../dashboard/routes/Dashboard"; +import { DashboardRouteWithRealm } from "../../dashboard/routes/Dashboard"; import environment from "../../environment"; import { createNamedContext } from "../../utils/createNamedContext"; import useRequiredContext from "../../utils/useRequiredContext"; @@ -22,9 +20,11 @@ export const RealmContext = createNamedContext( export const RealmContextProvider: FunctionComponent = ({ children }) => { const { adminClient } = useAdminClient(); const recentUsed = useMemo(() => new RecentUsed(), []); - const routeMatch = useRouteMatch( - DashboardRouteWithRealm.path - ); + const routeMatch = useMatch({ + path: DashboardRouteWithRealm.path, + end: false, + }); + const realmParam = routeMatch?.params.realm; const realm = useMemo( () => realmParam ?? environment.loginRealm,