mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: useEvent
This commit is contained in:
parent
e09935230d
commit
a642a701d0
1 changed files with 10 additions and 4 deletions
|
|
@ -143,13 +143,19 @@ RawGitako.defaultProps = {
|
|||
|
||||
export const SideBar = connect(SideBarCore)(RawGitako)
|
||||
|
||||
function useOnPJAXComplete(onPJAXComplete: () => void, deps: React.DependencyList = []) {
|
||||
function useEvent<
|
||||
T extends {
|
||||
addEventListener: Function
|
||||
}
|
||||
>(target: T, event: string, callback: () => void, deps: React.DependencyList = []) {
|
||||
React.useEffect(() => {
|
||||
window.addEventListener('pjax:complete', onPJAXComplete)
|
||||
return () => window.removeEventListener('pjax:complete', onPJAXComplete)
|
||||
}, [onPJAXComplete, ...deps])
|
||||
window.addEventListener('pjax:complete', callback)
|
||||
return () => window.removeEventListener('pjax:complete', callback)
|
||||
}, [callback, ...deps])
|
||||
}
|
||||
|
||||
const useOnPJAXComplete = useEvent.bind(null, window, 'pjax:complete')
|
||||
|
||||
function renderAccessDeniedError() {
|
||||
return (
|
||||
<div className={'description'}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue