Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Query useMutation: is not assignable to parameter of type "mutationkey"

I have api call that looks like

const getMutationService = () => {
  return {
    createMeme: async (
      _private: string,
      templateId: string,
      file: Blob,
      memeText?: string,
      title?: string,
      tags?: Array<string>,
    ): Promise<MemeCreateMemeResponse | undefined> => {
      return await memeApi.memePost({
        _private,
        templateId,
        file,
        memeText,
        title,
        tags,
      });
    },
  };
};

and I am calling this in another hook like

const mutationService = getMutationService();



 const { mutate: createMeme } = useMutation(mutationService.createMeme);

Its throwing an error of

Argument of type '(_private: string, templateId: string, file: Blob, memeText?: string, title?: string, tags?: Array) => Promise<MemeCreateMemeResponse | undefined>' is not assignable to parameter of type 'MutationKey'.

I have done other mutation calls with the same pattern. Why is this one throwing this mutation key error? Confused

like image 593
dev Avatar asked Nov 27 '25 16:11

dev


1 Answers

useMutation can only accept one parameter. If you need multiple parameters, please use an object.

like image 181
TkDodo Avatar answered Nov 29 '25 12:11

TkDodo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!