Skip to content

Instantly share code, notes, and snippets.

@Wintus
Last active November 19, 2019 09:03
Show Gist options
  • Save Wintus/c7fcfda1a735e6f7f89ce4c54c1d5d8e to your computer and use it in GitHub Desktop.
Save Wintus/c7fcfda1a735e6f7f89ce4c54c1d5d8e to your computer and use it in GitHub Desktop.
React Native Navigation Hooks
import {useNavigation} from 'react-navigation-hooks';
import {NavigationStackProp} from 'react-navigation-stack';
// extract B from A & B where A is given.
type InferIntersection<I, T> = I extends T & infer U ? U : never;
// NavigationStackProp does not pass parameter S; use concrete type.
// https://github.com/react-navigation/stack/blob/df9e8675760517154d0323b24175750d543e5be8/src/types.tsx#L31-L34
type RT = ReturnType<typeof useNavigation>;
const useNavigationEx = <P>() => useNavigation() as RT & P;
type StackDiff = InferIntersection<NavigationStackProp, RT>;
// TODO: workaround
export const useStackNavigation = (): NavigationStackProp =>
useNavigationEx<StackDiff>();
@Wintus
Copy link
Author

Wintus commented Nov 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment