Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

Commit

Permalink
fix generic type of useNavigationParam
Browse files Browse the repository at this point in the history
  • Loading branch information
Avery Pierce committed Mar 3, 2021
1 parent 3c77a53 commit 017b5f3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EventType,
} from 'react-navigation';

export function useNavigation<S>(): NavigationScreenProp<S & NavigationRoute> {
export function useNavigation<S, P = NavigationParams>(): NavigationScreenProp<S & NavigationRoute, P> {
const navigation = useContext(NavigationContext) as any; // TODO typing?
if (!navigation) {
throw new Error(
Expand All @@ -29,10 +29,10 @@ export function useNavigation<S>(): NavigationScreenProp<S & NavigationRoute> {
return navigation;
}

export function useNavigationParam<T extends keyof NavigationParams>(
paramName: T
export function useNavigationParam<Params extends NavigationParams = NavigationParams>(
paramName: keyof Params
) {
return useNavigation().getParam(paramName);
return useNavigation<unknown, Params>().getParam(paramName) as Params[typeof paramName] | undefined
}

export function useNavigationState() {
Expand Down

0 comments on commit 017b5f3

Please sign in to comment.