Andruroshan
Andruroshan

Reputation: 123

How to send the state values from one screen to another screen

I dont know how to send the value from one screen to another screen,

Here is my code

<TouchableOpacity 
style={{
        width:"100%",
        height:"200%",
        alignItems:'center',
        justifyContent:'center',
        backgroundColor:'green'
      }} 
onPress={() =>
this.props.navigation.navigate(
                                'cart',
                                { food  : this.state.item,
                                  amount    : this.state.ruppess 
                                } 
                            )

}>
<Text>Cart</Text>
</TouchableOpacity>

Upvotes: 0

Views: 54

Answers (1)

kamal verma
kamal verma

Reputation: 516

Try this

to send the value

this.props.navigation.navigate(
                             "cart",{
                                     food: this.state.item,
                                     amount: this.state.ruppes
                                     }
                               );

to get the value on next screen

const food = this.props.navigation.getParam("food", "");
const amount = this.props.navigation.getParam("amount", "");

Upvotes: 1

Related Questions