Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to use classes and props at the same time javascript react native

$
0
0

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() {    ...  }}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>