use-mutation | Run side-effects safely in React | Frontend Utils library
kandi X-RAY | use-mutation Summary
kandi X-RAY | use-mutation Summary
Specially useful to run requests against an API, and combined with SWR.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of use-mutation
use-mutation Key Features
use-mutation Examples and Code Snippets
Community Discussions
Trending Discussions on use-mutation
QUESTION
Scenario
When a user is authenticated (isAuthenticated
booelan ref):
- Check if a user has preferences by a graphql call to the backend (
useViewerQuery
) - If there are no preferences for the user set the default (
useSetPreferenceDefaultMutation
)
Problem
Both the query and the mutation work correctly in the graphql Playground and in the Vue app. They have been generated with the graphql codegenerator which uses useQuery and useMutation in the background.
The issue we're having is that we can't define the correct order. Sometimes useSetPreferenceDefaultMutation
is executed before useViewerQuery
. This resets the user's settings to the defaults and it not the desired behavior.
Also, on a page refresh all is working correctly. However, when closing an reopening the page it always calls useSetPreferenceDefaultMutation
.
Code
...ANSWER
Answered 2020-Oct-02 at 14:34Thanks to comment from @xadm it's fixed now by using the onResult event hook on the query, so it will execute the mutation afterwards.
onResult(handler): Event hook called when a new result is available.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install use-mutation
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page