Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hook] useScroll #29

Open
alber0905 opened this issue Jan 29, 2020 · 0 comments
Open

[Hook] useScroll #29

alber0905 opened this issue Jan 29, 2020 · 0 comments
Assignees

Comments

@alber0905
Copy link

Hook para recuperar fácilmente el scroll de la página.

interface Scroll {
  x: number;
  y: number;
}

const useScroll = (): Scroll => {
  const [scroll, setScroll] = useState<Scroll>({ x: 0, y: 0 });
  const updateScroll = (): void => setScroll({ x: window.scrollX, y: window.scrollY });
  useEffect((): (() => void) => {
    window.addEventListener('scroll', updateScroll);
    updateScroll();
    return (): void => {
      window.removeEventListener('scroll', updateScroll);
    };
  }, []);
  return scroll;
};

export default useScroll;
@alber0905 alber0905 changed the title [HOOK] useScroll [Hook] useScroll Jan 29, 2020
@miguelBinpar miguelBinpar self-assigned this Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants