import { useEffect, useRef } from 'react';

export default (fn) => {
  const fnRef = useRef();
  fnRef.current = fn;

  useEffect(() => {
    const resize = () => {
      const { clientWidth, clientHeight } = document.documentElement;
      fnRef.current(clientWidth, clientHeight);
    };

    window.addEventListener('resize', resize);

    return () => window.removeEventListener('resize', resize);
  }, []);
};
