Incremental update example question
I'm having trouble with the incremental update example. It does not seem to work as described. I am calling
createTodo
, which:
1. Calls todosCollection.insert
.
2. The onInsert
funtion returns { refetch: false }
, which means the optimistic update is immediately rolled back and the UI will not show the new state.
3. api.createTodo
is called and the todo is created on the server
4. writeDelete
is called and errors out since the item with id: tempId
was never added to the store.
The todo has been created on the server, but the UI is left in an error state.
Alternatively, if in the onInsert
you call todosCollection.utils.writeInsert(transaction.mutations[0].changes)
with the tempId, it will succeed, but then if there is an error actually saving it to the server then the change will never be rolled back unless you also add a writeDelete(tempId)
in the catch
.
Full example: github
What is the right pattern to use?0 Replies