Fix custom responsive hook
This commit is contained in:
parent
f431470e7b
commit
eea47821f1
979
pnpm-lock.yaml
generated
979
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user