Replies: 1 comment 1 reply
-
Ofc we can create a custom hook, but it would be nice if it existed internally. const useEditableName = () => {
const queryClient = useQueryClient();
const { data: name, isLoading } = useQuery({
queryKey: ['name'],
queryFn: fetchName
});
const { mutate: updateName } = useMutation({
mutationFn: updateNameInDB,
onSuccess: (newName) => {
// Update the cache immediately
queryClient.setQueryData(['name'], newName);
}
});
return {
name,
isLoading,
updateName
};
}; |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
For the single variable in database I have to use two different hooks (useQuery and useMutation) for fetching and mutating it.
It would be nice if there exists a hook which provides both the functionality in one hook.
For ex. I have a settings page in my application, and in that page i have a field called "Name".
Now i want user to be able to edit this field (Name). For this functionality to be implemented i would have to use useQuery to fetch existing name, and then use useMutation when user edits the name and clicks save. if there existed a single hook with several boolean variable it would have been much easier.
ex.
useQueryMutate which returns { isFetching, isMutating, isLoading, value, isError }
I would be interested to collaborate on this, but let me know what do you think guys.
Beta Was this translation helpful? Give feedback.
All reactions