Skip to content

Instantly share code, notes, and snippets.

@emeraldsanto
Last active August 19, 2020 23:07
Show Gist options
  • Save emeraldsanto/4b98d6b20b5429d283df7253005a6030 to your computer and use it in GitHub Desktop.
Save emeraldsanto/4b98d6b20b5429d283df7253005a6030 to your computer and use it in GitHub Desktop.
Typings for a more efficient way to use React Navigation with TypeScript.
import { FC } from "react";
import { RouteProp } from "@react-navigation/native";
import { StackNavigationProp } from "@react-navigation/stack";
/**
* Interface mapping screen names to their navigation params.
*/
export interface ScreenArguments extends Record<string, object | undefined> { }
/**
* Interface representing the props passed in to every screen by React Navigation.
*/
export interface NavigationScreenProps<TName extends keyof ScreenArguments> {
navigation: StackNavigationProp<ScreenArguments, TName>;
route: RouteProp<ScreenArguments, TName>;
}
/*
* Shorthand type for function components, should be used instead of `React.FC` to
* ensure screens and their parameters are properly typed.
*/
export type NavigationScreen<TName extends keyof ScreenArguments> = FC<NavigationScreenProps<TName>>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment