Is there any idea how to send props to child component from parent in react native.I heard in react about that.But dont know in react-native. All I want is when user presses AddToCart button which actually is wrapped within onpress event of touchable opacity, props should be sent to another page.Somone told me about using redux, but I think this can happen in react-native too.
Bottom Line: There's a button when it pressed the props should be sent to another page.
ItemDetais page
From where props should be send.
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) {
// this.props.navigation.navigate('Cart', {id: data.cart.id})
// was using this method.But when I directly open
// cart page it gives me an error undefined is not
// an object..blah blah
}
})
})
}
<TouchableOpacity onPress={()=> { this.cart() }} >
<Text>AddToCart<Text>
</TouchableOpacity>
CartPage
where props should be recieve.
componentDidMount() {
let cart_id = this.props.navigation.state.params.id;
// above method is just total waste.
API.getCartItem(cart_id)
.then((response) => {
if (response) {
this.setState({
data: response
});
} else {
alert('no data')
}
})
}