Skip to content

Conversation

@eomttt
Copy link
Contributor

@eomttt eomttt commented Apr 6, 2021

useMutation has void return type but in code has not

In my code

  const onMutate = () => {
    const previous = queryClient.getQueryData<CartProductsDataType>(queryKey);
    return previous;
  };
  const onError = (error: any, variable: AddOptionItem, context: CartProductsDataType | undefined) => {
    queryClient.setQueryData(queryKey, context);
  };

  return useMutation(QueryKey.CARTS, mutateFn, {
    onMutate,
    onError,
  });

onMutate return CartProductsDataType or undefind because of getQueryData but in useMutation error!!!
because useMutation onMutate function type only return Promise<Context> or Context not has undefined
so i try to add undefined type in onMutate return type

@vercel
Copy link

vercel bot commented Apr 6, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/7Gk7TUZ6ULvRQpH5xo2mey2qmRqY
✅ Preview: https://react-query-git-fork-eomttt-master-tannerlinsley.vercel.app

@eomttt eomttt changed the title Add void return type in onMutate Add undefined return type in onMutate Apr 6, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 6, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2dbc134:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

@TkDodo TkDodo merged commit a88d80f into TanStack:master Apr 10, 2021
@tannerlinsley
Copy link
Member

🎉 This PR is included in version 3.13.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants