Найти баг в компоненте ресайзера

Тут либо есть баг, либо что-то не так с кодом.

const WindowSizeTracker = () => {
    const [windowWidth, setWindowWidth] = useState(window.innerWidth);
    const [windowHeight, setWindowHeight] = useState(window.innerHeight);

    useEffect(() => {
        window.addEventListener('resize', () => {
            setWindowWidth(window.innerWidth);
            setWindowHeight(window.innerHeight);
        });
    });

    return (
        <div>
            <h2>Ширина окна: {windowWidth}px</h2>
            <h2>Высота окна: {windowHeight}px</h2>
        </div>
    );
};

Оставьте комментарий