split stuff up

This commit is contained in:
MapleLeaf
2021-12-29 17:12:42 -06:00
parent 401fcd2f16
commit eef9d3a0bc
5 changed files with 45 additions and 38 deletions

View File

@@ -0,0 +1,11 @@
import { useEffect } from "react"
export function useWindowEvent<EventType extends keyof WindowEventMap>(
type: EventType,
handler: (event: WindowEventMap[EventType]) => void,
) {
useEffect(() => {
window.addEventListener(type, handler)
return () => window.removeEventListener(type, handler)
})
}