Created
November 21, 2019 13:53
-
-
Save FreddyPoly/552d181a25780b90e38941672933bc4c to your computer and use it in GitHub Desktop.
[REACT NATIVE] Exemple component avec accès navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react" | |
import { View, Text } from "react-native" | |
import { NavigationScreenProps } from "react-navigation" // <=== | |
export interface Props extends NavigationScreenProps<{}> { // <=== | |
propsVar: any; | |
} | |
export interface State { | |
stateVar: any; | |
} | |
export class Asset extends React.Component<Props, State> { | |
constructor(props: Props) { | |
super(props); | |
this.state = { | |
stateVar: 'Variable du state', | |
} | |
} | |
componentDidMount = () => { | |
// Ce component a maintenant accès à l'objet "navigation" | |
this.props.navigation.navigate('screen1'); | |
} | |
render() { | |
return ( | |
<View> | |
<Text>State: { this.state.stateVar }</Text> | |
<Text>Props: { this.props.propsVar }</Text> | |
</View> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment