Answers for "react detect screen size"

0

react detect screen size

import { useState, useEffect } from 'react';

function getWindowDimensions() {
  const { innerWidth: width, innerHeight: height } = window;
  return {
    width,
    height
  };
}

export default function useWindowDimensions() {
  const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());

  useEffect(() => {
    function handleResize() {
      setWindowDimensions(getWindowDimensions());
    }

    window.addEventListener('resize', handleResize);
    return () => window.removeEventListener('resize', handleResize);
  }, []);

  return windowDimensions;
}
Posted by: Guest on September-03-2020
1

react js get screen size

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

Code answers related to "react detect screen size"

Code answers related to "Javascript"

Browse Popular Code Answers by Language