Answers for "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
0

how to get window size in react js

const Component = () => {
  const { height, width } = useWindowDimensions();

  return (
    <div>
      width: {width} ~ height: {height}
    </div>
  );
}
Posted by: Guest on December-29-2020
1

react js get screen size

console.log(window.innerHeight);
Posted by: Guest on December-17-2020

Code answers related to "window.innerwidth in react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language