Reputation: 6839
In reducer I have:
if (action.type === 'remove_item') {
delete state.itemsList[action.itemId];
return {
...state
}
But now componentWillReceiveProps(nextProps)
can't see difference between:
this.props.items !== nextProps.items
I know that this happens because I changed state in reducer directly
but don't know how to propagate this change now so nextProps will have new state data?
Upvotes: 1
Views: 864
Reputation: 6039
Try
...state.itemsList.filter((_, index) => index !== action.itemId)
So you're not mutating the original state, instead creating a new array.
Upvotes: 3
Reputation: 3384
It's not showing changes because state object is immutable and you are directly doing an operation on the immutable object.
Try this:
if (action.type === 'remove_item') {
var list = state.itemsList.splice();
list[action.itemId] = null
return {
...state,
itemsList: list,
}
Cheers :)
Upvotes: 3