Reputation: 31
Several of my colleagues are spreading the part of the state in mapStateToProps.
const mapStateToProps = (state = {}) =>
({
addUserForm: { ...state.addUser.addUserForm },
addUserLabels: { ...state.addUser.addUserLabels }
});
Is it OK to do it? It duplicates the part of the state. And when actual Redux state changes the component won't get re rendered. Right? Correct me if I am wrong please.
Upvotes: 1
Views: 28
Reputation: 2996
Because the spread is using state
that is passed into mapStateToProps
the component will still re-render when the state changes. I am not sure what is gained by the use of this spread syntax. Looks to achieve exactly the same thing as:
const mapStateToProps = (state = {}) =>
({
addUserForm: state.addUser.addUserForm,
addUserLabels: state.addUser.addUserLabels
});
Upvotes: 1