fix: attach useEvent target and event

This commit is contained in:
EnixCoda 2019-11-18 18:01:26 +08:00
parent 583c99baee
commit 8e5761bffb
No known key found for this signature in database
GPG key ID: FE06F5DFC1C9B8E4

View file

@ -146,11 +146,12 @@ export const SideBar = connect(SideBarCore)(RawGitako)
function useEvent<
T extends {
addEventListener: Function
removeEventListener: Function
}
>(target: T, event: string, callback: () => void, deps: React.DependencyList = []) {
React.useEffect(() => {
window.addEventListener('pjax:complete', callback)
return () => window.removeEventListener('pjax:complete', callback)
target.addEventListener(event, callback)
return () => target.removeEventListener(event, callback)
}, [callback, ...deps])
}