-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathhooks.ts
36 lines (29 loc) · 929 Bytes
/
hooks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react'
import * as Bus from './bus'
import { useErrorOverlayReducer } from '../shared'
import { useErrorHandlers } from '../../errors/use-error-handler'
import { Router } from '../../../router'
export const usePagesDevOverlay = () => {
const [state, dispatch] = useErrorOverlayReducer('pages')
useErrorHandlers(dispatch)
React.useEffect(() => {
Bus.on(dispatch)
const { handleStaticIndicator } =
require('./hot-reloader-client') as typeof import('./hot-reloader-client')
Router.events.on('routeChangeComplete', handleStaticIndicator)
return function () {
Router.events.off('routeChangeComplete', handleStaticIndicator)
Bus.off(dispatch)
}
}, [dispatch])
const onComponentError = React.useCallback(
(_error: Error, _componentStack: string | null) => {
// TODO: special handling
},
[]
)
return {
state,
onComponentError,
}
}