useWindowWidth

UseWindowWidthExample

src/prod/window/useWindowWidth.ts

import React from 'react';



export const useWindowWidth = () => {
	const [windowWidth, setWindowWidth] = React.useState(0);

	React.useEffect(() => {
		function updateSize () {
			setWindowWidth(window.innerWidth);
		}

		window.addEventListener("resize", updateSize);
		updateSize();

		return () => window.removeEventListener("resize", updateSize);
	}, []);

	return [windowWidth];
};

dist/prod/window/useWindowWidth.js

import React from 'react';
export const useWindowWidth = () => {
    const [windowWidth, setWindowWidth] = React.useState(0);
    React.useEffect(() => {
        function updateSize() {
            setWindowWidth(window.innerWidth);
        }
        window.addEventListener("resize", updateSize);
        updateSize();
        return () => window.removeEventListener("resize", updateSize);
    }, []);
    return [windowWidth];
};

src/prod/window/useWindowWidth.ts

import React from 'react';



export const useWindowWidth = () => {
	const [windowWidth, setWindowWidth] = React.useState(0);

	React.useEffect(() => {
		function updateSize () {
			setWindowWidth(window.innerWidth);
		}

		window.addEventListener("resize", updateSize);
		updateSize();

		return () => window.removeEventListener("resize", updateSize);
	}, []);

	return [windowWidth];
};