Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

window.innerHeight react js

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

//////

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

  return (
    <div>
      width: {width} ~ height: {height}
    </div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: download file from api vue 
Javascript :: js replace multiple 
Javascript :: ajax jquery 
Javascript :: react app js 
Javascript :: javascript regex cheat sheet 
Javascript :: @ media min and max width material ui 
Javascript :: express receive post 
Javascript :: how to add seconds to time in js 
Javascript :: react cheat sheet 
Javascript :: js check if function is a constructor 
Javascript :: genius lyrics api 
Javascript :: prisma seed 
Javascript :: js pad 2 
Javascript :: javascript copy to clipboard 
Javascript :: random number in javascript between two numbers 
Javascript :: reset parsley validation 
Javascript :: save canvas as image from website 
Javascript :: jquery form data 
Javascript :: create csv file javascript 
Javascript :: covid-19 
Javascript :: default selected radio button angular material 
Javascript :: add required attribute javascript 
Javascript :: javascript loop backwards through array 
Javascript :: how to find repeated characters in a string in javascript 
Javascript :: object json parse javascript 
Javascript :: react antd form disable submit button 
Javascript :: timestamp convert moment vue 
Javascript :: continuous scrolling js 
Javascript :: how to merge two objects into one in javascript 
Javascript :: javascript indexof with condition 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =