Skip to content

Commit

Permalink
fix: allow to call useKbsDisableGlobal outside of context
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Feb 6, 2023
1 parent dc43792 commit 5ff073a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/component/KbsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const kbsContext = createContext<KbsState>(initialKbsState);

const kbsDispatchContext = createContext<Dispatch<KbsAction> | null>(null);

export function useKbsUncheckedDispatch() {
return useContext(kbsDispatchContext);
}

export function useKbsDispatch() {
const dispatch = useContext(kbsDispatchContext);
if (!dispatch) {
Expand Down
6 changes: 3 additions & 3 deletions src/component/hooks/useKbsDisableGlobal.ts
Original file line number Diff line number Diff line change
@@ -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]);
Expand Down

0 comments on commit 5ff073a

Please sign in to comment.