Add second returned value to useMutation ?
See original GitHub issueWIth the Mutation component from Apollo. you can do something like this:
const AddTodo = () => {
let input;
return (
<Mutation mutation={ADD_TODO}>
{(addTodo, { data }) => (
<div>
<form
onSubmit={e => {
e.preventDefault();
addTodo({ variables: { type: input.value } });
input.value = "";
}}
>
<input
ref={node => {
input = node;
}}
/>
<button type="submit">Add Todo</button>
</form>
</div>
)}
</Mutation>
);
};
could the useMutation hook be modified like so?
const [doMutation, { data, loading, error }] = useMutation(...);
Issue Analytics
- State:
- Created 5 years ago
- Reactions:27
- Comments:23 (9 by maintainers)
Top Results From Across the Web
Mutations in Apollo Client - Apollo GraphQL Docs
The useMutation hook accepts an options object as its second parameter. Here's an example that provides some default values for GraphQL variables :....
Read more >useMutation | TanStack Query Docs
The value returned from this function will be passed to both the onError and onSettled functions in the event of a mutation failure...
Read more >Mastering Mutations in React Query | TkDodo's blog
For this use-case, React Query offers the useMutation hook. ... which can also add values to an array, but it will return a...
Read more >How to declare useMutation return type in 'react-query'
I think you intended to use Params as TVariables but you are actually using it as TError when you put it in the...
Read more >Mutations | Redux Toolkit
See useMutation for the hook signature and additional details. Frequently Used Mutation Hook Return Values. The useMutation hook returns a ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I just published an alpha version of 0.5.0 with #135 merged-in. It’s available as
react-apollo-hooks@alpha.Sorry, I pasted that right from the Apollo Docs.
I personally use
loadinganderrorsmore thandatabut all three are returned (like<Query />)The main use cause is for showing a loading state while waiting for a response (like in a form). Optimistic update is a fantastic alternative, but sometimes you need to be “honest” about the loading state (or errors).