TanStackT
TanStack15mo ago
2 replies
dangerous-fuchsia

TanstackQuery useMutation example

Hey folks, would like your takes/assistance on a silly one. I'm using TSQ for a small SolidJS project and I'm trying to create a mutation but it seems like the newer version does not support the previous version in which we passed a mutationFn and a mutationKey . This is the way I usually go about it. I've got the follow function to create a thing:

const createThing = async (thing: object) => {
  try {
    return await callPost("/create-thing", thing);
  } catch (error) {
    return handleApiError(error as AxiosError);
  }
};


And I'm trying to create a new mutation using the following:

function useCreateThingMutation() {
  return createMutation({
    mutationKey: ["createThing"],
    mutationFn: createThing,
  });
}

But what i'm getting is an error stating that both mutationKey and mutationFn does not exist in our types anymore....Also the examples in the docs do not cover mutation creation anymore. How did ya'll work your way around this change?

P.S. Using "@tanstack/solid-query": "^5.59.17",

Edit: I know I can just use
createQuery
and achieve the same?? result but I really liked how we had separate actions to handle data fetching and data manipulation.
Was this page helpful?