UNPKG

react-custom-hooks-utils

Version:

This library contains a collection of reusable React custom hooks to simplify state management, side effects, and user interactions.

25 lines (19 loc) 541 B
import { useState, useEffect } from 'react'; function useWindowSize() { const [windowSize, setWindowSize] = useState({ width: window.innerWidth, height: window.innerHeight, }); useEffect(() => { const handleResize = () => { setWindowSize({ width: window.innerWidth, height: window.innerHeight, }); }; window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); return windowSize; } export default useWindowSize;