Skip to content

Instantly share code, notes, and snippets.

@osartun
Created June 14, 2019 14:03
Show Gist options
  • Save osartun/268a03e80951a505e47746153219866c to your computer and use it in GitHub Desktop.
Save osartun/268a03e80951a505e47746153219866c to your computer and use it in GitHub Desktop.
Code graveyard
import { useEffect } from 'react'
export const useOnResize = (
onResize: (this: Window, ev: UIEvent) => unknown,
options?: boolean | AddEventListenerOptions | undefined
) => {
useEffect(() => {
if (typeof window === 'object') {
window.addEventListener(
'resize',
onResize,
options !== undefined ? options : { passive: true }
)
return () => window.removeEventListener('resize', onResize)
}
return undefined
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment