diff --git a/src/component/KbsProvider.tsx b/src/component/KbsProvider.tsx index 40c04e1..e60985e 100644 --- a/src/component/KbsProvider.tsx +++ b/src/component/KbsProvider.tsx @@ -43,6 +43,10 @@ export const kbsContext = createContext(initialKbsState); const kbsDispatchContext = createContext | null>(null); +export function useKbsUncheckedDispatch() { + return useContext(kbsDispatchContext); +} + export function useKbsDispatch() { const dispatch = useContext(kbsDispatchContext); if (!dispatch) { diff --git a/src/component/hooks/useKbsDisableGlobal.ts b/src/component/hooks/useKbsDisableGlobal.ts index 483704e..63706eb 100644 --- a/src/component/hooks/useKbsDisableGlobal.ts +++ b/src/component/hooks/useKbsDisableGlobal.ts @@ -1,11 +1,11 @@ import { useEffect } from 'react'; -import { useKbsDispatch } from '../KbsProvider'; +import { useKbsUncheckedDispatch } from '../KbsProvider'; export function useKbsDisableGlobal(disabled = true) { - const kbsDispatch = useKbsDispatch(); + const kbsDispatch = useKbsUncheckedDispatch(); useEffect(() => { - if (!disabled) return; + if (!disabled || !kbsDispatch) return; kbsDispatch({ type: 'DISABLE_GLOBAL' }); return () => kbsDispatch({ type: 'ENABLE_GLOBAL' }); }, [kbsDispatch, disabled]);