How to pass state to component React Native

Viewed 4960

I am new to React Native and really cant figure out why I am not able to pass a state from one component to another

export default class questions extends Component {
constructor(props){
    super(props);
    this.state={
        name: "stupidCount",
        val: 1}            
}

render(){
    const { navigate } = this.props.navigation;
    const { name2 } = this.state;
    return(
        <View style={styles.box}>
            <TouchableOpacity onPress={() => navigate('Question1',  stupidCount={name2})} >
                <Text style={styles.h1}> Question 1 </Text>
            </TouchableOpacity>

Second component, 'Question1'

export default class Question2 extends Component {
render(){
    const { navigate } = this.props.navigation;
    console.log(stupidCount.val);
    return(
        <View style={styles.box}>
            <Text style={styles.h1}>Question 2 </Text>
            <Text> state test {stupidCount.val}</Text>

Thanks a lot in advance

1 Answers
Related