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
docs: improve incremental updates example in query-collection docs (TanStack#703)
* docs: improve incremental updates example in query-collection docs
Replace confusing manual optimistic update pattern with familiar
onInsert/onUpdate handler pattern. Show how to:
- Use persistence handlers (onInsert, onUpdate) like regular collections
- Return { refetch: false } to avoid unnecessary refetches
- Sync server-computed fields using direct writes within handlers
This makes the example more approachable and consistent with the
rest of the documentation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* docs: remove unnecessary writeDelete from query-collection example
Optimistic state is automatically removed when the mutation handler
returns, so there's no need to manually delete optimistic items. The
handler just needs to write the server response to the synced data
store, and when it completes, the optimistic state is automatically
replaced.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>
When the server returns computed fields (like server-generated IDs or timestamps), you can use the `onInsert` handler with `{ refetch: false }` to avoid unnecessary refetches while still syncing the server response:
228
+
227
229
```typescript
228
-
// Handle server responses after mutations without full refetch
229
-
const createTodo =async (todo) => {
230
-
// Optimistically add the todo
231
-
const tempId =crypto.randomUUID()
232
-
todosCollection.insert({ ...todo, id: tempId })
233
-
234
-
try {
235
-
// Send to server
236
-
const serverTodo =awaitapi.createTodo(todo)
237
-
238
-
// Sync the server response (with server-generated ID and timestamps)
0 commit comments