how to handle lists
I would like to render a list of multiple sorted Todos on the same, from a query that calls
getAllTodos.
Inside this list, I would like to be able to update a single Todo, from a mutation that calls updateSingleTodo, while also optimistically updating the Todo item in the list.
When I call queryClient.setQueryData(['todos', { id: 5 }], newTodo), does React Query automatically know what Todo to update in the list of Todos?
Or will I need to optimistically update the entire list of todos by replacing a single todo in that list?
This would also apply to updating the list of todos with the result of a mutation too.
Thanks!2 Replies
fascinating-indigo•3y ago
You have to do it manually because react-query doesn't know what relationship the data in your cache has with each other.
dependent-tanOP•3y ago
thanks for the clarification!