mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-10 13:15:25 +03:00
Add typing
This commit is contained in:
parent
a66b96345b
commit
cf5cbbc7fd
@ -64,12 +64,15 @@ export function usePersistedOverlayState<S extends string>(
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useHashState(): [string | undefined, (value: string) => void] {
|
export function useHashState<S extends string>(): [
|
||||||
|
S | undefined,
|
||||||
|
(value: S) => void,
|
||||||
|
] {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const setHash = useCallback(
|
const setHash = useCallback(
|
||||||
(value: string | undefined) => {
|
(value: S | undefined) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
navigate(location.pathname);
|
navigate(location.pathname);
|
||||||
} else {
|
} else {
|
||||||
@ -81,7 +84,10 @@ export function useHashState(): [string | undefined, (value: string) => void] {
|
|||||||
[location, navigate],
|
[location, navigate],
|
||||||
);
|
);
|
||||||
|
|
||||||
const hash = useMemo(() => location.hash.substring(1), [location.hash]);
|
const hash = useMemo(
|
||||||
|
() => location.hash.substring(1) as unknown as S,
|
||||||
|
[location.hash],
|
||||||
|
);
|
||||||
|
|
||||||
return [hash, setHash];
|
return [hash, setHash];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user