Created
June 14, 2019 14:03
-
-
Save osartun/268a03e80951a505e47746153219866c to your computer and use it in GitHub Desktop.
Code graveyard
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 } 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