You muterule an array of
tasks which pass into the component. When new properties after the upgrade store, in the component in which you deliver it are checked:
this.props.tasks === nextProps.tasks; // true
It returns
true, as this same array and the component is not updated.
Correct way:
export default function addDelete(state = initialState, action){
switch (action.type) {
case "ADD_TASK":
return {
...state
tasks: [...state.tasks, {{id: action.id, time : action.time, task: action.task}}],
};
case "DELETE_TASK":
return {
...state
tasks: [...state.tasks.filter(task => task.id != action.id)],
};
case "SET_ACSSES":
return {
...state
add: !state.add
};
default:
return state;
}
}
But it will be even better if improve their
actionCreators. Put the payload in the key
payload:
export default function add(time, task, id){
if(!task || !time){
return {
type: "SET_ERROR",
payload: "Error, invalid data"
};
}
return{
type: "ADD_TASK",
payload: {
id: id,
time: time,
task: task,
},
}
}
export const deleteTask = id => ({
type: 'DELETE_TASK',
payload: id
});
Reducer then code will be like this:
export default function addDelete(state = initialState, action) {
const { type, payload } = action;
switch (type) {
case "ADD_TASK":
return {
...state
tasks: [...state.tasks, payload],
};
case "DELETE_TASK":
return {
...state
tasks: [...state.tasks.filter(task => task.id != payload)],
};
case "SET_ACSSES":
return {
...state
add: !state.add
};
default:
return state;
}
}