How to update a pending mutation
I'm currently facing a scenario where I'm using a QR code scanner that triggers an axios.post request on each scan. To optimize responsiveness, I've implemented onMutate to proceed without waiting for the API response. However, I also need to allow users to edit this information even when offline.
The current online workflow functions correctly: upon scanning, a toast appears, and clicking it redirects the user to a form where they can edit the information. However, I'm unsure how to handle offline scenarios where I might need to edit a pending mutation.
Any insights or suggestions on how to manage offline edits alongside pending mutations would be greatly appreciated.
2 Replies
absent-sapphire•15mo ago
editing creates a new mutation, so when offline, the
/create
would fire first, and then /edit
would come afterwards. Have a look at scoped mutations too to avoid them running in parallelabsent-sapphire•15mo ago
Mutations | TanStack Query React Docs
Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects. For this purpose, TanStack Query exports a useMutation hook.
Here's an example of a mutation that adds a new todo to the server: