feat: add click any where hooks

This commit is contained in:
unix
2020-03-25 02:35:20 +08:00
parent 269a2bfae5
commit 7915c74525

View File

@@ -0,0 +1,14 @@
import { useEffect } from 'react'
const useClickAnyWhere = (
handler: (event: Event) => void,
) => {
useEffect(() => {
const callback = (event: Event) => handler(event)
document.addEventListener('click', callback)
return () => document.removeEventListener('click', callback)
}, [handler])
}
export default useClickAnyWhere