undefined params in v7 #12271
-
|
according to the docs i've created simple navigation: navigation.ts: const RootStack = createNativeStackNavigator({
screens: {
FirstScreen: {
screen: FirstScreen,
},
SecondScreen: {
screen: SecondScreen,
},
},
});
export const Navigation = createStaticNavigation(RootStack);
export type RootStackParamList = StaticParamList<typeof RootStack>;then i import RootStackParamList in import {RootStackParamList} from './navigation.ts';
declare global {
namespace ReactNavigation {
interface RootParamList extends RootStackParamList {}
}
}and finally in my component i use the hook ...
import {useNavigation} from '@react-navigation/native';
...
...
const {navigate} = useNavigation();
...
const onPress = () => navigate('SecondScreen', {userName})
...But i have an issue: then i tried to pass param list directly to the "createNativeStackNavigator" export type RootParamList = {
FirstScreen: undefined;
SecondScreen: {userName: string};
};
const RootStack = createNativeStackNavigator<RootParamList>({
screens: {
FirstScreen: {
screen: FirstScreen,
},
SecondScreen: {
screen: SecondScreen,
},
},
});
export const Navigation = createStaticNavigation(RootStack);
export type RootStackParamList = StaticParamList<typeof RootStack>;But this also didn’t help. "StaticParamList" doesn’t infer params types. "RootStackParamList" is always nvm with The question is: how to type a static implementation with params? P.S.: The way it works for me is by using… instead of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
How are your screens components defined? |
Beta Was this translation helpful? Give feedback.
How are your screens components defined?