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

[Question] Please show example how create another hook based on that #29

Closed
borm opened this issue May 14, 2020 · 1 comment
Closed

Comments

@borm
Copy link

borm commented May 14, 2020

as example, i wanna create useResize hook, correct me please if im doing it wrong

const getSize = () => ({
  width: window.innerWidth,
  height: window.innerHeight,
});

export default function useResize(onResize = () => {}) {
  function handleResize() {
    if (typeof onResize === 'function') onResize(getSize());
  }

  // We need get window size on first call
  useEffect(() => {
    handleResize();
  }, []);

  // Then we are subscribe to window `resize`
  useEventListener('resize', handleResize);
}
@srmagura
Copy link
Collaborator

Hey @borm, your code looks right to me. Is it not working correctly?

@borm borm closed this as completed May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants