summaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-query-selector-all.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-19 19:46:24 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-19 19:46:24 +0200
commitbbd63400f94b43fde04449e0c71d14763d893e6a (patch)
tree057055dce19fc71c7c2e2fa05b691144224dfbd0 /src/utils/hooks/use-query-selector-all.tsx
parent806004ab79ac4e1cb49cef93ab3f35a08c5c82b5 (diff)
refactor: rewrite Prism hooks and providers
It avoid some hydratation errors on project pages (not in article however) and the hooks are now reusable.
Diffstat (limited to 'src/utils/hooks/use-query-selector-all.tsx')
-rw-r--r--src/utils/hooks/use-query-selector-all.tsx12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/utils/hooks/use-query-selector-all.tsx b/src/utils/hooks/use-query-selector-all.tsx
index dbeec90..6ac8a08 100644
--- a/src/utils/hooks/use-query-selector-all.tsx
+++ b/src/utils/hooks/use-query-selector-all.tsx
@@ -1,14 +1,22 @@
+import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
+/**
+ * Use `document.querySelectorAll`.
+ *
+ * @param {string} query - A query.
+ * @returns {NodeListOf<HTMLElementTagNameMap[T]|undefined>} - The node list.
+ */
const useQuerySelectorAll = <T extends keyof HTMLElementTagNameMap>(
query: string
-) => {
+): NodeListOf<HTMLElementTagNameMap[T]> | undefined => {
const [elements, setElements] =
useState<NodeListOf<HTMLElementTagNameMap[T]>>();
+ const { asPath } = useRouter();
useEffect(() => {
setElements(document.querySelectorAll(query));
- }, [query]);
+ }, [asPath, query]);
return elements;
};