Help with optimistic updates #2696
Replies: 2 comments 3 replies
-
Hello @ConnorMarble, Can you share a sandbox with with your code? That would make it easier to identify the problem. |
Beta Was this translation helpful? Give feedback.
-
The "updating a single todo" example assumes that you have a detail view where you fetch a single todo. If you don't have that and only work with one query where you have an Array of todos, all you need to do to update an element in the list is, well, find the element in the array and update it, something like:
this will put the newTodo into the array at the position that matches by id. if you still have troubles, please post a codesandbox reproduction.
React Query has a cache depending on query keys, associated with a fetching function. If you only have a list query that fetches a list, any invalidation on that entry will fetch the list. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am following the example here, but I am having trouble filling in the blanks. Right now I have a gql query to grab all todos from my server and it works. However I am trying to update a single todo item using the example in the link, but in my cache I have only a single query called ["Todos"]. So the value previousTodo comes out undefined.
Is there a full project with all of these use cases available? Or does anyone know how to resolve this issue? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions