Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to set state when change viewport react

import React, { useLayoutEffect, useState } from 'react';

function useWindowSize() {
  const [size, setSize] = useState([0, 0]);
  useLayoutEffect(() => {
    function updateSize() {
      setSize([window.innerWidth, window.innerHeight]);
    }
    window.addEventListener('resize', updateSize);
    updateSize();
    return () => window.removeEventListener('resize', updateSize);
  }, []);
  return size;
}

function ShowWindowDimensions(props) {
  const [width, height] = useWindowSize();
  return <span>Window size: {width} x {height}</span>;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how get one value of array of object in javascript 
Javascript :: hide label chratjs 
Javascript :: navigate-to-an-anchor-on-another-page 
Javascript :: image base64 to file javascript 
Javascript :: jquery 3.6.0 cdn 
Javascript :: js remove query param from url 
Javascript :: for each js 
Javascript :: js save files 
Javascript :: aos js 
Javascript :: apa itu this pada javascript 
Javascript :: javascript hover event 
Javascript :: remove element from an array 
Javascript :: generate random string javascript 
Javascript :: disable strict mode angular 
Javascript :: react native image source local file 
Javascript :: object element by index javascript 
Javascript :: get element by class 
Javascript :: js import export es5 
Javascript :: select add option js 
Javascript :: how to wait until a variable is set javascript 
Javascript :: Error serializing `.list Data` returned from `getStaticProps` 
Javascript :: componentdidupdate 
Javascript :: javascript send post 
Javascript :: javascript xmldocument to string 
Javascript :: console log object js 
Javascript :: nuxt head script content 
Javascript :: react bootstrap card 
Javascript :: copy dict js 
Javascript :: vue dev server proxy not working 
Javascript :: javascript ascending and descending 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =