mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-26 20:06:26 -08:00
19 lines
576 B
TypeScript
19 lines
576 B
TypeScript
import { useEffect } from 'react';
|
|
import { useSetAtom } from 'jotai';
|
|
import { useLocation } from 'react-router-dom';
|
|
import { useNavToActivePathAtom } from '$state/hooks/navToActivePath';
|
|
|
|
export const useNavToActivePathMapper = (navId: string) => {
|
|
const location = useLocation();
|
|
const setNavToActivePath = useSetAtom(useNavToActivePathAtom());
|
|
|
|
useEffect(() => {
|
|
const { pathname, search, hash } = location;
|
|
setNavToActivePath({
|
|
type: 'PUT',
|
|
navId,
|
|
path: { pathname, search, hash },
|
|
});
|
|
}, [location, setNavToActivePath, navId]);
|
|
};
|