Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { useEffect } from 'react';
- export function useScrollToHash(trigger: boolean) {
- useEffect(() => {
- console.log(' = = = =Ececuting scroll!!!')
- let { hash } = window.location;
- hash = hash ? hash.substring(1) : null;
- if (hash) {
- const el = document.getElementById(hash);
- if (el) {
- setTimeout(() => el.scrollIntoView(), 0);
- }
- }
- }, [trigger]); // I don't know what parameter to pass to this custom hook, so it will run only once - after initial query has eneded. Otherwise this hook will run multiple times and will scroll even when no need
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement