react-redux 從 store 刪除指定id物件
action 定義 export function removeCartItem(id){ return{ type:REMOVE_CART_ITEM, id:id }; } reducer 寫法 export default (state = initstate(), action) => { console.log('userReducer was called with state', state, 'and action', action); switch (action.type) { case GET_CART_ITEMS: return assign({}, state, { cartItems: action.items }); case REMOVE_CART_ITEM: return assign({},{ cartItems:state.cartItems.filter( //return value without target id (item) => { console.log('act:'+action.id); console.log('item:'+item.id); return item.id !== action.id; } ) }); default: return state; } }; 說明 聚焦在 case REMOVE_CART_ITEM: 這邊 1. assign()這個函式會在第一個參數new...