Open felipexperto opened 3 months ago
Code:
import { useState, useEffect } from 'react'; export default function useWindowSize() { const [windowSize, setWindowSize] = useState({ height: undefined, width: undefined, }); useEffect(() => { function handleResize() { setWindowSize({ height: window.innerHeight, width: window.innerWidth, }); } window.addEventListener('resize', handleResize); handleResize(); return () => window.removeEventListener('resize', handleResize); }, []); return windowSize; }
Test:
Code:
Test: