passProps does not work with redux
Hello! I'm having trouble getting the passProps when navigation pushes to a component screen with redux, I don't know if I've done it wrong or I'm just missing something. I just want to state my issue and I hope someone could help me.
I keep getting suggestions that when registering a screen component with redux it should be like this:
Navigation.registerComponentWithRedux('com.app.ScreenName', ()=> ScreenName, Provider, store);
But I've followed the latest documentation and it noted that Navigation.registerComponentWithRedux() is deprecated and it should actually be like this now:
Navigation.registerComponent('example.ComponentName', () => () =>
(
<Provider store={store}>
<ComponentName {...props}/>
</Provider>
), () => ComponentName);
I've tried registering other components with this without putting any props and it works. But my real problem Is this...
FindPlace.js
...
itemSlectedHandler = key => {
const selPlace = this.props.places.find(place => {
return place.key === key;
});
Navigation.push('route-builder.FindPlaceScreen', {
component: {
id: 'route-builder.PlaceDetailScreen',
name: 'route-builder.PlaceDetailScreen',
passProps: {
selectedPlace: selPlace
},
options: {
topBar: {
title: {
text: selPlace.name
}
}
}
}
});
};
render() {
console.log(this.props);
return(
<View>
<PlaceList places={this.props.places} onItemSelected={this.itemSlectedHandler} />
</View>
);
}
...
App.js
...
Navigation.registerComponent('route-builder.PlaceDetailScreen', () => () =>
(
<Provider store={store}>
<PlaceDetailScreen />
</Provider>
), () => PlaceDetailScreen);
...
PlaceDetail.js
import React, {Component} from 'react';
import { View, Image, Text, StyleSheet, TouchableOpacity} from 'react-native';
import {connect} from 'react-redux';
import Icon from 'react-native-vector-icons/Ionicons';
import {deletePlace} from '../../store/actions/index';
...
placeDeletedHandler = () => {
this.props.onDeletePlace(this.props.selectedPlace.key);
Navigation.pop('route-builder.PlaceDetailScreen');
};
render() {
console.log(this.props);
return (
<View style={styles.container}>
<View>
<Image
source={this.props.selectedPlace.image}
style={styles.placeImage} />
<Text style={styles.placeName}>{this.props.selectedPlace.name}</Text>
</View>
<View>
<TouchableOpacity onPress={this.placeDeletedHandler}>
<View style={styles.deleteButton}>
<Icon size={30} name="ios-trash" color="red" />
</View>
</TouchableOpacity>
</View>
</View>
);
};
...
const mapDispatchToProps = dispatch => {
return {
onDeletePlace: (key) => dispatch(deletePlace(key))
};
};
export default connect(null, mapDispatchToProps)(PlaceDetail);
I've run this without redux and it worked, but when I tried adding redux, it only got the onDeletePlace as props and didn't really get the passProps when navigation pushed the screen to the component.
I hope this would be understandable enough, I just want some help. Thank you good people!
We use the issue tracker exclusively for bug reports and feature requests. This issue appears to be a general usage or support question. Instead, please ask a question on Stack Overflow with the react-native-navigation tag.