Reactjs 如何向用户发送警报而不将其发送到react navigation中的另一个页面?
我正在react-native中开发电子商务应用程序。需要帮助吗 我正在使用react导航进行路由 是否知道如何向用户发送通知,告知他/她的项目已添加到购物车,而不将其发送到购物车页面,但发送购物车idReactjs 如何向用户发送警报而不将其发送到react navigation中的另一个页面?,reactjs,react-native,Reactjs,React Native,我正在react-native中开发电子商务应用程序。需要帮助吗 我正在使用react导航进行路由 是否知道如何向用户发送通知,告知他/她的项目已添加到购物车,而不将其发送到购物车页面,但发送购物车id cart(){ let product_id = this.props.navigation.state.params.id; AsyncStorage.getItem('cart_id') .then((_id) => API.post_dat
cart(){
let product_id = this.props.navigation.state.params.id;
AsyncStorage.getItem('cart_id')
.then((_id) =>
API.post_data(_id, product_id )
.then((data) => {
if(data){
alert(data.product_name + 'data success');
}
// If I use this,
// this.props.navigation.navigate("Cart", {id:data.id);
// This send an user to cart page as well.
else{
alert(data.error.message + 'failed')
}
})
.catch(err => alert(err))
})
}
<TouchableOpacity
onPress={() => {
this.cart()
}}
>
</TouchableOpacity>
cart(){
让product_id=this.props.navigation.state.params.id;
AsyncStorage.getItem('cart\u id')
。然后(_id)=>
API.post_数据(_id,产品_id)
。然后((数据)=>{
如果(数据){
警报(data.product_name+“数据成功”);
}
//如果我用这个,
//this.props.navigation.navigate(“购物车”{id:data.id);
//这也会将用户发送到购物车页面。
否则{
警报(data.error.message+“失败”)
}
})
.catch(err=>alert(err))
})
}
{
this.cart()
}}
>
怎么样?但是警报如何将id发送到另一个页面?您是否使用诸如redux之类的数据管理系统?如果是这样,只需将此值设置为存储并将其传递给另一个路由/组件。如果不是,则应将状态与所需值一起提升到某个共同的父组件(),这是非常困难和不同的..或者您是否告诉我如何使用上面提到的代码..谢谢。。。!只有两种方法可以将参数传递到屏幕:使用参数导航到此屏幕,或将所需数据存储在路由器上方并作为道具传递