Answer the question
In order to leave comments, you need to log in
How to update a component when the state changes?
There is a component
function Tasks(tasksData) {
return (
<React.Fragment>
tasksData.map((task) => (
<Task
key={task.ID}
task={task}
/>)
)
</React.Fragment>
)
}
Answer the question
In order to leave comments, you need to log in
The first rule of Redux is to always spread a mutable value, otherwise redux doesn't know you've changed it. The splice method you are using does not change the array, and map is meaningless in this case. The correct code would be:
const index = state.tasksData.findIndex(({ ID }) => ID === payload.ID)
if (index > -1) return {
...state,
tasksData:
state.tasksData.slice(0, index).concat(
state.tasksData.slice(index + 1))
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question