Does a custom action also invoke collection-level handlers if you use the collection's default operations in its useMutate method? #1144
Unanswered
aihdene-genetec
asked this question in
Q&A
Replies: 1 comment
-
|
Yes, that assumption is correct: For this pattern, do not have both paths write the same backend change. Either: onMutate: (postId) => {
postCollection.update(postId, draft => {
draft.likeCount += 1
draft.likedByMe = true
})
},
mutationFn: async (postId) => {
await api.posts.like(postId)
await postCollection.utils.refetch()
}and make sure the collection-level |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am reading through the documentation and came through the optimistic custom actions:
Documentation states that you can use custom actions when:
The action calls
api.posts.like(postId)but it also callspostCollection.updatewhich from my understanding might invokeonUpdatecollection-level handler. Which means that you'd have two potential calls to the back-end? Or am I incorrect in my assumption?Thank you for your time and consideration.
Beta Was this translation helpful? Give feedback.
All reactions