Skip to content

Instantly share code, notes, and snippets.

@savio777
Last active December 31, 2023 03:05
Show Gist options
  • Save savio777/428345da496d7965d7187fdb42dcea86 to your computer and use it in GitHub Desktop.
Save savio777/428345da496d7965d7187fdb42dcea86 to your computer and use it in GitHub Desktop.
Example Type React-native navigation
import { useRoute } from "@react-navigation/native";
const ExampleComponent = () => {
const route = useRoute<IStackAllScreensProps<"LoginToken">>();
const { userId } = route.params;
return <></>;
};
export default ExampleComponent;
import { NavigatorScreenParams } from '@react-navigation/native';
import { NativeStackNavigationProp, NativeStackScreenProps } from '@react-navigation/native-stack';
declare type ILoggedOffPages = {
Onboarding: undefined;
Login: undefined;
LoginToken: {
userId: string;
sendBy: CodeCanBeSendBy;
};
TermsOfUse: undefined;
Support: undefined;
SignUp: {
cpf: string;
};
};
declare type IBottomTabLoggedInPages = {
Home: undefined;
Riviera: undefined;
MyWallet: undefined;
Properties: undefined;
Benefits: undefined;
};
declare type ITabNavigatorBottomTab = NavigatorScreenParams<IBottomTabLoggedInPages>;
declare type IStackLoggedInPages = {
TabNavigator: ITabNavigatorBottomTab;
MyProfile: undefined;
AboutTheApp: undefined;
NewsList: undefined;
NewsDetail: {
newsId: string;
newsType: string;
};
};
declare type IStackAllScreens = IStackLoggedInPages & ILoggedOffPages;
declare type IStackAllScreensNavigationProp = NativeStackNavigationProp<IStackAllScreens>;
declare type IStackAllScreensProps<T extends keyof IStackAllScreens> = NativeStackScreenProps<
IStackAllScreens,
T
>['route'];
declare global {
namespace ReactNavigation {
interface RootParamList extends IStackAllScreens {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment