-
|
right now onChange={() => {
todoCollection.update(todo.id,
(draft) => {
draft.completed = !draft.completed;
},
);
}}the mutation state is returned by the update function, but I want to change my ui based on it in react // something like react-query
const {mutate: updateTodo, isOptimistic} useLiveMutation(() => {
todoCollection.update(todo.id,
(draft) => {
draft.completed = !draft.completed;
},
);
return todoCollection
})
return <input type="checkbox" styles={isOptimistic ? ... : ...}/> |
Beta Was this translation helpful? Give feedback.
Answered by
Asjas
Nov 26, 2025
Replies: 1 comment 6 replies
-
|
You use live queries https://tanstack.com/db/latest/docs/guides/live-queries |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are a couple of states that
useLiveQueryprovides, one ispersisting. Use that to show some type of UI to the user that the data hasn't been synced yet before they leave the page.https://tanstack.com/db/latest/docs/guides/error-handling#transaction-states-and-error-information
If they leave and the mutation fails and they log back in, there wouldn't be a way for
useLiveQueryto resume because it's in-memory, the failed sync won't show up.It sounds like you want a different solution to this, something like redis that can temporarily store the request and status that can be separately checked and can retry on its own without the user being signed in, or atleast can show a user that …