diff --git a/packages/client/src/hooks/useCurrentLibrary.tsx b/packages/client/src/hooks/useCurrentLibrary.tsx index 065afa57d..907993bb0 100644 --- a/packages/client/src/hooks/useCurrentLibrary.tsx +++ b/packages/client/src/hooks/useCurrentLibrary.tsx @@ -1,4 +1,5 @@ import { PropsWithChildren, createContext, useCallback, useContext, useMemo } from 'react'; +import { useNavigate } from 'react-router'; import { subscribe, useSnapshot } from 'valtio'; import { useBridgeQuery } from '../rspc'; import { valtioPersist } from '../stores'; @@ -34,6 +35,8 @@ export function onLibraryChange(func: (newLibraryId: string | null) => void) { // this is a hook to get the current library loaded into the UI. It takes care of a bunch of invariants under the hood. export const useCurrentLibrary = () => { + const navigate = useNavigate(); + const currentLibraryUuid = useSnapshot(currentLibraryUuidStore).id; const ctx = useContext(CringeContext); if (ctx === undefined) @@ -66,9 +69,13 @@ export const useCurrentLibrary = () => { } }); - const switchLibrary = useCallback((libraryUuid: string) => { - currentLibraryUuidStore.id = libraryUuid; - }, []); + const switchLibrary = useCallback( + (libraryUuid: string) => { + currentLibraryUuidStore.id = libraryUuid; + navigate('/'); + }, + [navigate] + ); // memorize library to avoid re-running find function const library = useMemo(() => {