I have problem with updating component when remove element from redux state.
my component:
const mapStateToProps = state => ({
products: state.shoppingBasket.list,
});
const ShoppingBasket = React.createClass({
propTypes: {
removeProduct: React.PropTypes.func.isRequired,
products: React.PropTypes.array,
open: React.PropTypes.func.isRequired,
},
removeFromBasket(index, name) {
this.props.removeProduct(index);
},
render() {
return (
<div>
{this.props.products.map((product, index) => (
<div key={index}>
product.name
<button onClick={() => this.RemoveFromBasket(index)}
</div>
);
)}
</div>
);
},
});
export default connect(mapStateToProps, actions)(ShoppingBasket);
my reducer:
export default function shoppingBasket(
state = {
list: [],
},
action
) {
let tmp = [];
switch (action.type) {
case SHOPPING_BASKET_ADD:
return { list: [...state.list, action.payload.product] };
case SHOPPING_BASKET_REMOVE:
tmp = state.list;
tmp.splice(action.payload.index, 1);
return { list: tmp };
default:
return state;
}
}
When insert element in redux state my component successfuly update, but when i click on button and call removeFromBasket element was remove from redux state but commponent shouldn't update.