diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-19 19:46:24 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-19 19:46:24 +0200 |
| commit | bbd63400f94b43fde04449e0c71d14763d893e6a (patch) | |
| tree | 057055dce19fc71c7c2e2fa05b691144224dfbd0 /src/utils/hooks/use-code-blocks-theme.tsx | |
| parent | 806004ab79ac4e1cb49cef93ab3f35a08c5c82b5 (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-code-blocks-theme.tsx')
| -rw-r--r-- | src/utils/hooks/use-code-blocks-theme.tsx | 22 |
1 files changed, 0 insertions, 22 deletions
diff --git a/src/utils/hooks/use-code-blocks-theme.tsx b/src/utils/hooks/use-code-blocks-theme.tsx deleted file mode 100644 index beb7b29..0000000 --- a/src/utils/hooks/use-code-blocks-theme.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { usePrismTheme } from '@utils/providers/prism-theme'; -import { useRouter } from 'next/router'; -import { RefObject, useEffect, useState } from 'react'; -import useIsMounted from './use-is-mounted'; - -const useCodeBlocksTheme = (el: RefObject<HTMLDivElement>) => { - const [preElements, setPreElements] = useState<NodeListOf<HTMLPreElement>>(); - const isMounted = useIsMounted(el); - const { setCodeBlocks } = usePrismTheme(); - const { asPath } = useRouter(); - - useEffect(() => { - const result = document.querySelectorAll<HTMLPreElement>('pre'); - setPreElements(result); - }, [asPath]); - - useEffect(() => { - isMounted && preElements && setCodeBlocks(preElements); - }, [isMounted, preElements, setCodeBlocks]); -}; - -export default useCodeBlocksTheme; |
