Fix custom responsive hook

This commit is contained in:
Sam Becker 2023-11-07 00:42:50 -06:00
parent f431470e7b
commit eea47821f1
2 changed files with 501 additions and 488 deletions

979
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,10 @@ import { useEffect } from 'react';
export default function RedirectOnDesktop({
redirectPath,
shouldPrefetch = true,
}: {
redirectPath: string
shouldPrefetch?: boolean
}) {
const router = useRouter();
@ -15,13 +17,17 @@ export default function RedirectOnDesktop({
const isDesktop = useIsDesktop();
router.prefetch(redirectPath);
useEffect(() => {
if (shouldPrefetch) {
router.prefetch(redirectPath);
}
}, [router, shouldPrefetch, redirectPath]);
useEffect(() => {
if (isDesktop && pathname !== redirectPath) {
router.push(redirectPath);
}
}, [isDesktop, pathname, redirectPath, router]);
}, [router, isDesktop, pathname, redirectPath]);
return null;
}