Redux store is updating correctly but react components props are not. I checked redux global state with a remote dev tool and it's updating as expected.
But when i check component props with react-devtools it isn't updating.
If i call getUserPublis() in a higher order component (index e.g) then mapStateToProps maps these props correctly, but when i create a new item it's not mapped (but its correctly updated into the store).
It's like if mapStateToProps() is not being called when redux state update
class Profile extends Component {
static navigationOptions = ({navigation, screenProps}) => ({
title: 'Perfil',
headerRight: <HeaderButton navigation={navigation}/>,
});
componentDidMount(){
getUserPublis(this.props.userData.ownPublis)
}
onPressCard = (publi) => {
this.props.navigation.navigate('cardDescription', {
data: publi,
user: props.userName
})
}
maybeRenderAddButton = () => {
if (this.props.userData.isCommerce){
return(
<FloatingButton
icon="md-add"
color="white"
onPress={() => this.props.navigation.navigate('offerNew', {
title: "Crear anuncio"
})}
/>
)
} else {
return console.log('no hay add button')
}
}
render(){
this.maybeRenderAddButton()
if (this.props.publis.length === 0) {
return(
<Text> Loading </Text>
)
}
return (
<ScrollView>
{
this.props.publis.map((publi, index) => {
return(
<CardGeneral
key={index}
onPressCard={() => onPressCard(publi)}
data={publi}
user={this.props.user.displayName}
/>
)
}
)
}
</ScrollView>
);
}
}
function mapStateToProps(state) {
return {
user: state.auth.user,
userData: state.firestore.userData,
publis: state.publis
}
}
export default connect(mapStateToProps)(Profile)
Reducer:
const initialState = []
function publis(state = initialState, action) {
switch (action.type) {
case 'FIRESTORE_PUBLI_SNAPSHOT': {
return [
...state,
action.payload.data
]
}
default:
return state
}
}
export default publis
console.log
into mapStateToProps function to see whether it's called when state.publis changes. If it's not, something is wrong with redux implementation (maybe missing a Provided or reducer not included in rootStore). – Václav Zeman