how to get window size in react js
const Component = () => {
const { height, width } = useWindowDimensions();
return (
<div>
width: {width} ~ height: {height}
</div>
);
}
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;
}
Also in JavaScript:
- check unique object in array javascript site:stackoverflow.com
- just number regex
- check if type is blob javascript
- filereader check file type
- regex to get part of word nodejs
- How to Set focus to first text input in a bootstrap modal after shown
- default value of functin atribute
- mongodb replace string
- angular injector.create example
- javascript array flatten
- ajax laravel get values from form
- discord function promise
- solr regex expression
- single node elasticsearch with enable security basic in docker
- js array clone
- vuejs cdn
- app.js:38650 [Vue warn]: Failed to mount component: template or render function not defined
- check object has key javascript
- mask date of birth/ dob in javascript
- bajar archivos node
- math js min
- WHAT IS NODE IN DOM
- javascript current date add 30 days
- string json to class c#