You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
526 B

  1. /* eslint react/prop-types: 0 */
  2. import { useState } from 'react';
  3. import { useRef } from 'react';
  4. import { useEffect } from 'react';
  5. export const useBbox = () => {
  6. const ref = useRef();
  7. const [bbox, setBbox] = useState({});
  8. const set = () =>
  9. setBbox(ref && ref.current ? ref.current.getBoundingClientRect() : {});
  10. useEffect(() => {
  11. set();
  12. window.addEventListener('resize', set);
  13. return () => window.removeEventListener('resize', set);
  14. }, []);
  15. return [bbox, ref];
  16. };