Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import { useEffect } from 'react';
  2.  
  3. export function useScrollToHash(trigger: boolean) {
  4. useEffect(() => {
  5. console.log(' = = = =Ececuting scroll!!!')
  6. let { hash } = window.location;
  7. hash = hash ? hash.substring(1) : null;
  8. if (hash) {
  9. const el = document.getElementById(hash);
  10. if (el) {
  11. setTimeout(() => el.scrollIntoView(), 0);
  12. }
  13. }
  14. }, [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
  15.  
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement