Created
December 17, 2021 20:29
-
-
Save vczb/144b9de19f8ed4d08769399734226c5a to your computer and use it in GitHub Desktop.
useReziseWindow react custom hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from 'react' | |
| export default function useReziseWindow() { | |
| const [windowWidth, setWindowWidth] = useState<number | null>() | |
| useEffect(() => { | |
| const onResize = () => { | |
| setWindowWidth(window?.innerWidth) | |
| } | |
| window.addEventListener('resize', onResize) | |
| return () => { | |
| window.removeEventListener('resize', onResize) | |
| } | |
| }, []) | |
| return windowWidth | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example usage: