aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-redirection.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-12-01 19:34:58 +0100
committerArmand Philippot <git@armandphilippot.com>2023-12-04 19:00:04 +0100
commit53b63ac27c2275262db9a04be02210a3287aa71d (patch)
tree814968e10cad25e1b34ab251de42ac5ecb82b346 /src/utils/hooks/use-redirection.tsx
parent11e3ee75fcab0ab54b2bc1713a402c5cc3070c2d (diff)
refactor(pages): refine Blog pages
* replace usePostsList with useArticlesList to keep names coherent * remove useIsMounted hook * rewrite useRedirection hook * add redirect in getStaticProps to avoid unecessary fetching * move Pagination component in a noscript tag * use hooks to refresh thematics and topics lists * complete Cypress tests
Diffstat (limited to 'src/utils/hooks/use-redirection.tsx')
-rw-r--r--src/utils/hooks/use-redirection.tsx31
1 files changed, 0 insertions, 31 deletions
diff --git a/src/utils/hooks/use-redirection.tsx b/src/utils/hooks/use-redirection.tsx
deleted file mode 100644
index 5a677e2..0000000
--- a/src/utils/hooks/use-redirection.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { useRouter } from 'next/router';
-import { useEffect } from 'react';
-
-export type RouterQuery = {
- param: string;
- value: string;
-};
-
-export type UseRedirectionProps = {
- /**
- * The router query.
- */
- query: RouterQuery;
- /**
- * The redirection url.
- */
- redirectTo: string;
-};
-
-/**
- * Redirect to another url when router query match the given parameters.
- *
- * @param {UseRedirectionProps} props - The redirection parameters.
- */
-export const useRedirection = ({ query, redirectTo }: UseRedirectionProps) => {
- const router = useRouter();
-
- useEffect(() => {
- if (router.query[query.param] === query.value) router.push(redirectTo);
- }, [query, redirectTo, router]);
-};