onUpdate option #369
-
I think am doing something wrong here but my implementation below works for getKey: (item) => item.id,
// schema: WatchlistResponseSchema,
onInsert: async ({ transaction }) => {
const { original, modified } = transaction.mutations[0];
await createWatchlist(modified);
},
onUpdate: async ({ transaction }) => {
const { original, modified } = transaction.mutations[0];
await updateWatchlist(modified);
}, Am wondering if am calling if (editingWatchlist) {
myWatchlistsCollection(qc).update(editingWatchlist.id, (draft) => {
draft.title = "new title";
});
} else {
myWatchlistsCollection(qc).insert(data as any);
} am on the latest version {
"@tanstack/query-db-collection": "^0.1.2",
"@tanstack/react-db": "^0.1.0"
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Huh that looks right. You're not getting any error or other notice in the console? Maybe it's the same as #366 — perhaps we shipped a regression recently... |
Beta Was this translation helpful? Give feedback.
-
Have you tried any of the examples? |
Beta Was this translation helpful? Give feedback.
-
Its whatever you return for getKey so in this case, the id of the item. |
Beta Was this translation helpful? Give feedback.
Ah yeah, you want to use a weakmap cache when creating collections on the fly to ensure you get back only one instance.