Skip to content

Instantly share code, notes, and snippets.

@kp-gists
Created January 16, 2023 09:10
Show Gist options
  • Save kp-gists/6cfb18a70172b34a4bcc7a462257c406 to your computer and use it in GitHub Desktop.
Save kp-gists/6cfb18a70172b34a4bcc7a462257c406 to your computer and use it in GitHub Desktop.
useWindowSize w useOnScreen
import { useState } from "react"
import useEventListener from "../13-useEventListener/useEventListener"
export default function useWindowSize() {
const [windowSize, setWindowSize] = useState({
width: window.innerWidth,
height: window.innerHeight,
})
useEventListener("resize", () => {
setWindowSize({ width: window.innerWidth, height: window.innerHeight })
})
return windowSize
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment