Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
}
Comment

react js get screen size

  console.log(window.innerHeight);
Comment

PREVIOUS NEXT
Code Example
Javascript :: lazy loading pagination react npm 
Javascript :: aos js 
Javascript :: prodigy math game add item by id 
Javascript :: math.rount 
Javascript :: jquery on load 
Javascript :: guid generator node 
Javascript :: encodeurl in javascript 
Javascript :: sleep function js 
Javascript :: min of an array javascript 
Javascript :: add border to view react native 
Javascript :: javascript prevent space from scrolling 
Javascript :: add jquery cdn 
Javascript :: js get sum of array of objects 
Javascript :: clear session storage on refresh 
Javascript :: javascript set timeout 
Javascript :: eslint unexpected console statement 
Javascript :: delay javascript function 
Javascript :: convert a string to an integer in javascript 
Javascript :: infinite for loop javascript 
Javascript :: get element or class 
Javascript :: jquery data attribute 
Javascript :: how to print line break in javascript 
Javascript :: set cookie in node 
Javascript :: axios withcredentials 
Javascript :: Nuxt JS Adding script tag to particular page 
Javascript :: JavaScript how to put value 
Javascript :: convert object to boolean javascript 
Javascript :: Unexpected token a in JSON at position 
Javascript :: jquery serialize form data to object 
Javascript :: remove undefined from javascript array map 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =