0
votes

I've tried to use Redux in my react native application. I can definitely see that the value is updated by the reducers but my question is why it is not updating the properties of my class automatically?

I need to use getDerivedStateFromProps in order to populate my class properties. I expect that that the below:

const mapStateToProps = (state) => { return { email: state.user }

will automatically update me this.state.email with the value from the redux store but it doesn't. I need to doe the following to work:

static getDerivedStateFromProps(props, state) {return { user: props.user}}

1

1 Answers

0
votes

You can use directly reducer in your component. It also update automatically when the value change in reducer. For example, if you want to use user variable in your component then you can use it as below :

<Text>{this.props.user}</Text>

Now, when user variable value change in reducer, it automatically update in the <Text> component. You don't need to use this line :

static getDerivedStateFromProps(props, state) {return { user: props.user}}