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

Commit 017b5f3

Browse files
author
Avery Pierce
committed
fix generic type of useNavigationParam
1 parent 3c77a53 commit 017b5f3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Hooks.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
EventType,
1818
} from 'react-navigation';
1919

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

32-
export function useNavigationParam<T extends keyof NavigationParams>(
33-
paramName: T
32+
export function useNavigationParam<Params extends NavigationParams = NavigationParams>(
33+
paramName: keyof Params
3434
) {
35-
return useNavigation().getParam(paramName);
35+
return useNavigation<unknown, Params>().getParam(paramName) as Params[typeof paramName] | undefined
3636
}
3737

3838
export function useNavigationState() {

0 commit comments

Comments
 (0)