Reputation: 187
I am trying to unblock my brain around something
I have the following code
const kategorierReducer = (state = initState, action) => {
switch (action.type) {
case 'ADD_KATEGORI':
console.log(action.payload)
return [state + {action.payload}]
case 'LOAD_KATEGORI':
return action.payload;
case 'EDIT_KATEGORI':
return action.payload;
case 'DELETE_KATEGORI':
return null;
default:
return state
}
}
And my brain is blocked around the code in the case of 'ADD_KATEGORI', how to return the current state + the new object.
help?
Btw and offtopic, is it too hard to migrate to Apollo-GraphQL?
Upvotes: 1
Views: 43
Reputation: 9591
return [state + {action.payload}]
should be return {...state, ...action.payload}
Upvotes: 3