Advertisement
MARSHAL327

Untitled

May 22nd, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. import { useEffect, useState } from 'react';
  2.  
  3. export default function useWindowSize() {
  4. const [size, setSize] = useState([0, 0]);
  5.  
  6. function updateSize() {
  7. setSize([window.innerWidth, window.innerHeight]);
  8. }
  9.  
  10. useEffect(() => {
  11. window.addEventListener('resize', updateSize);
  12. updateSize();
  13.  
  14. return () => window.removeEventListener('resize', updateSize);
  15. }, []);
  16.  
  17. return size;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement