Skip to content

Commit

Permalink
feat: allow returning null or undefined to skip actions with dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Feb 21, 2021
1 parent 02a031e commit d6466b7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/core/src/useNavigationCache.tsx
Expand Up @@ -78,16 +78,15 @@ export default function useNavigationCache<
const { emit, ...rest } = navigation;

const dispatch = (
action: NavigationAction | ((state: State) => NavigationAction)
thunk:
| NavigationAction
| ((state: State) => NavigationAction | null | undefined)
) => {
const payload =
typeof action === 'function' ? action(getState()) : action;
const action = typeof thunk === 'function' ? thunk(getState()) : thunk;

navigation.dispatch(
typeof payload === 'object' && payload != null
? { source: route.key, ...payload }
: payload
);
if (action != null) {
navigation.dispatch({ source: route.key, ...action });
}
};

const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
Expand Down

0 comments on commit d6466b7

Please sign in to comment.