question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add second returned value to useMutation ?

See original GitHub issue

WIth 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:open
  • Created 5 years ago
  • Reactions:27
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

19reactions
trojanowskicommented, Apr 26, 2019

I just published an alpha version of 0.5.0 with #135 merged-in. It’s available as react-apollo-hooks@alpha.

13reactions
cvburgesscommented, Feb 23, 2019

Sorry, I pasted that right from the Apollo Docs.

I personally use loading and errors more than data but 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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found