diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-18 22:40:59 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-18 22:40:59 +0200 |
| commit | 584bd42f871d2e1618ca414749f09c38f0143a44 (patch) | |
| tree | 45c821eec2ad9c77d5bccf83057cfc0a7e22ba09 /src/utils/hooks/use-query-selector-all.tsx | |
| parent | b214baab3e17d92f784b4f782863deafc5558ee4 (diff) | |
chore: handle settings change
Diffstat (limited to 'src/utils/hooks/use-query-selector-all.tsx')
| -rw-r--r-- | src/utils/hooks/use-query-selector-all.tsx | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/hooks/use-query-selector-all.tsx b/src/utils/hooks/use-query-selector-all.tsx new file mode 100644 index 0000000..dbeec90 --- /dev/null +++ b/src/utils/hooks/use-query-selector-all.tsx @@ -0,0 +1,16 @@ +import { useEffect, useState } from 'react'; + +const useQuerySelectorAll = <T extends keyof HTMLElementTagNameMap>( + query: string +) => { + const [elements, setElements] = + useState<NodeListOf<HTMLElementTagNameMap[T]>>(); + + useEffect(() => { + setElements(document.querySelectorAll(query)); + }, [query]); + + return elements; +}; + +export default useQuerySelectorAll; |
