I was using const
so that I could the navigation
props for my screens. Now, I need to implement the componentDidMount()
, but I have to switch to a class to do that. How can I have it so I can have the navigation
props and class Component
functionalities at the same time?
Code example:
Navigation.ts
import { ParamListBase, RouteProp } from "@react-navigation/native";import { StackNavigationProp } from '@react-navigation/stack';export interface StackNavigationProps< ParamList extends ParamListBase, RouteName extends keyof ParamList = string> { navigation: StackNavigationProp<ParamList, RouteName>; route: RouteProp<ParamList, RouteName>; onPress: () => void;}export type Routes = { Screen1: undefined; Screen2: undefined; Screen3: undefined,};
Screen1.tsx
const Screen1 = ({ navigation }: StackNavigationProps<Routes, "Screen1">) => { ...}
How can I combine the above and below to include navigation
props and React.Component
?
class Screen1 extends React.Component {componentDidMount() { ... }}