Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

usewindowsize hook in nextjs

import { useEffect, useState } from 'react'

// Hook
export default function useWindowSize() {
  const [windowSize, setWindowSize] = useState({
    width: undefined,
    height: undefined,
  })
  useEffect(() => {
    // Handler to call on window resize
    function handleResize() {
      // Set window width/height to state
      setWindowSize({
        width: window.innerWidth,
        height: window.innerHeight,
      })
    }
    // Add event listener
    window.addEventListener('resize', handleResize)
    // Call handler right away so state gets updated with initial window size
    handleResize()
    // Remove event listener on cleanup
    return () => window.removeEventListener('resize', handleResize)
  }, []) // Empty array ensures that effect is only run on mount
  return windowSize
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: react native children type 
Typescript :: leaderstats roblox setup 
Typescript :: delete folder and its subfolders in python 
Typescript :: typescript iterate over enum 
Typescript :: google sheets concatenate 
Typescript :: if env variable exists bash 
Typescript :: yarn.ps1 cannot be loaded because running scripts is disabled on this system. 
Typescript :: how to add new index in array in typescript 
Typescript :: mat datepicker pt-br 
Typescript :: how to find the index of property in array of object in typescript 
Typescript :: ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. 
Typescript :: Define a list of optional keys for Typescript Record 
Typescript :: how to add new line at n typography 
Typescript :: Read file contents on module location 
Typescript :: add to classlist of element in typescript not applied the css styles 
Typescript :: print list without brackets int python 
Typescript :: react native elements input limit 
Typescript :: mongodb increment array item 
Typescript :: ionic pasword visible inside ion-input 
Typescript :: how to reset stats in diablo 2 
Typescript :: typescript type for jsx element 
Typescript :: mat auto complete floating issue 
Typescript :: mat-checkbox change 
Typescript :: recharts bar chart layout vertical 
Typescript :: sort array of objects by 2 key value 
Typescript :: typescript check if element in array 
Typescript :: regex ts 
Typescript :: date format in typescript 
Typescript :: instragram basic api Display 
Typescript :: typescript filter list by property 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =