Answers for "react hooks inside class component"

0

react hooks inside class component

import { useEffect, useState } from 'react';

export function useScreenWidth(): number {
  const [width, setWidth] = useState(window.innerWidth);

  useEffect(() => {
    const handler = (event: any) => {
      setWidth(event.target.innerWidth);
    };

    window.addEventListener('resize', handler);

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

  return width;
}
Posted by: Guest on August-17-2021

Code answers related to "react hooks inside class component"

Code answers related to "Javascript"

Browse Popular Code Answers by Language