如何将状态值从一个屏幕发送到另一屏幕

时间:2020-01-14 09:47:44

标签: react-native react-native-android

我不知道如何将值从一个屏幕发送到另一屏幕,

这是我的代码

<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>

1 个答案:

答案 0 :(得分:1)

尝试一下

发送值

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

在下一个屏幕上获取值

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