Answers for "deal with window innerwidth in react"

2

innerWidth react

const [width, setWidth]   = useState(window.innerWidth);
const [height, setHeight] = useState(window.innerHeight);
const updateDimensions = () => {
    setWidth(window.innerWidth);
    setHeight(window.innerHeight);
}
useEffect(() => {
    window.addEventListener("resize", updateDimensions);
    return () => window.removeEventListener("resize", updateDimensions);
}, []);
Posted by: Guest on July-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language