Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react detect page width

import React, { useState, useEffect } from 'react'

export default function ScreenSize() {
  const [windowDimenion, detectHW] = useState({
    winWidth: window.innerWidth,
    winHeight: window.innerHeight,
  })

  const detectSize = () => {
    detectHW({
      winWidth: window.innerWidth,
      winHeight: window.innerHeight,
    })
  }

  useEffect(() => {
    window.addEventListener('resize', detectSize)

    return () => {
      window.removeEventListener('resize', detectSize)
    }
  }, [windowDimenion])

  return (
    <div>
      <p>Width: <strong>{windowDimenion.winWidth}</strong></p>
      <p>Height: <strong>{windowDimenion.winHeight}</strong></p>
    </div>
  )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: cordova delete cache 
Javascript :: How to make HTML input tag only accept numerical values? in jsx 
Javascript :: how to change icon from play to pause in javascript 
Javascript :: js concatenate regex 
Javascript :: how to run a function infinite time in javascript 
Javascript :: react iterate over map 
Javascript :: split and join in node js 
Javascript :: some method javascript 
Javascript :: javascript onclick event 
Javascript :: accept only video in input type file below size 
Javascript :: add items to a react array in hooks 
Javascript :: get second element with a class jquery 
Javascript :: axios data fetch 
Javascript :: textarea onclick select all 
Javascript :: angular ionic capacitor nfc reader 
Javascript :: react native text align vertical center 
Javascript :: javascript select function 
Javascript :: Redux thunk and react redux 
Javascript :: javascript window.onpopstate example 
Javascript :: for in range javascript 
Javascript :: js convert string to date 
Javascript :: remove first element of array javascript 
Javascript :: MaterialStateProperty width 
Javascript :: Escaping double quotation in javascript 
Javascript :: react-native-community/blur 
Javascript :: javascript search for words in sentence examples 
Javascript :: read files in node js 
Javascript :: JavaScript find the shortest word in a string 
Javascript :: nextjs react native web typescript 
Javascript :: constructor function 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =