Skip to content

Instantly share code, notes, and snippets.

@FreddyPoly
Created November 21, 2019 13:53
Show Gist options
  • Save FreddyPoly/552d181a25780b90e38941672933bc4c to your computer and use it in GitHub Desktop.
Save FreddyPoly/552d181a25780b90e38941672933bc4c to your computer and use it in GitHub Desktop.
[REACT NATIVE] Exemple component avec accès navigation
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