what would be the thoughts on making optimistic mutations the default? #1084
Unanswered
AlexFrazer
asked this question in
General
Replies: 1 comment
-
As you said, I think it's fairly easy to extract that to a custom |
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.
-
It's generally well accepted that optimistic updates is a strong UI pattern. While react-query does have good support for optimistic updates, I would wonder if there's any better DX for making it feel like a "default behavior".
Currently it appears the steps are basically:
ReactQueryCacheProvider
with the common ancestor of each componentonMutate
in theuseMutation
queryCache
onSuccess
to trigger a refetch.onError
that the update has failed.My code looks something like this:
I can abstract this into a custom hook, yes, but it does seem a little... not ideal. I would wonder if there would be a concept in the lib of
useOptimisticMutation
. Perhaps a high level config could be provided to tell it what it means to optimistically update, maybe being provided a function to rollback changes and a generic function foronSuccess
/onError
Of course, I am by no means an expert on this. It was just a thought while using the library. Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions