You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update mutation.md & JSDocs documentation for API changes (#743)
* docs: update paced mutations API to match final implementation
Fixed the paced mutations documentation to reflect the final API from PR #704:
- Updated all examples to use the onMutate callback pattern
- Changed mutate() to accept variables directly instead of callbacks
- Added comprehensive explanation of unique queues per hook instance
- Clarified that each usePacedMutations() and createPacedMutations() call creates its own independent queue
- Provided examples showing how to share queues across components for use cases like email draft auto-save
This addresses the common confusion about whether mutations from different places share the same debounce/queue - they only do if you explicitly share the same instance.
* docs: fix JSDoc examples for paced mutations
Updated JSDoc comments to match the final paced mutations API:
- debounceStrategy: Changed useSerializedTransaction to usePacedMutations and added onMutate example
- throttleStrategy: Changed useSerializedTransaction to usePacedMutations and added onMutate examples
- createPacedMutations: Fixed mutationFn signature - it only receives { transaction }, not the variables
The mutationFn only receives transaction params, while onMutate receives the variables passed to mutate().
---------
Co-authored-by: Claude <noreply@anthropic.com>
**Each unique `usePacedMutations` hook call creates its own independent queue.** This is an important design decision that affects how you structure your mutations.
1143
+
1144
+
If you have multiple components calling `usePacedMutations` separately, each will have its own isolated queue:
1145
+
1146
+
```tsx
1147
+
function EmailDraftEditor1({ draftId }: { draftId:string }) {
In this example, mutations from `EmailDraftEditor1` and `EmailDraftEditor2` will be queued and processed **independently**. They won't share the same debounce timer or queue.
1183
+
1184
+
**To share the same queue across multiple components**, create a single `createPacedMutations` instance and use it everywhere:
With this approach, all mutations from both components share the same debounce timer and queue, ensuring they're processed in the correct order with a single debounce implementation.
1213
+
1214
+
**Key takeaways:**
1215
+
1216
+
- Each `usePacedMutations()` call = unique queue
1217
+
- Each `createPacedMutations()` call = unique queue
1218
+
- To share a queue: create one instance and import it everywhere you need it
1219
+
- Shared queues ensure mutations from different places are ordered correctly
1220
+
1128
1221
## Mutation Merging
1129
1222
1130
1223
When multiple mutations operate on the same item within a transaction, TanStack DB intelligently merges them to:
0 commit comments