Skip to content

How to update a list after mutating one of its records? #887

Answered by flybayer
johhansantana asked this question in Q&A
Discussion options

You must be logged in to vote

@johhansantana great question! We currently don't have anything special for this.

So you'll need to update the array and then call mutate(completedTodos) and mutate(uncompletedTodos).

I think immer would probably be useful here to create the new array data. Something like this:

import produce from "immer"

const newUncompletedTodos = produce(uncompletedTodos, draft => {
   draft.splice(indexOfCompletedTodo, 1)
})
mutate(newUncompletedTodos)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by johhansantana
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants