Multiple Unique Mutation Calls With Different Mutation Keys

I have to perform post API calls to send data multiple times. The data is from local storage so it's in a form of an array. I will loop trough it and perform mutation. Here's the hook:

export default function useSendStory({
  idStory,
  idChapter,
}: {
  idStory: number | undefined;
  idChapter: number | undefined;
}) {
  return useMutation({
    mutationKey: queryKeys.sendStory({idStory, idChapter}),

    mutationFn: uploadStory,

    onSuccess: data => {
      console.log(data);
    },
  });
}


With the current approach, every time I perform the call, I have to recreate the hook since it's gonna have uniqueidStory and idChapter.

How can I pass its unique data such as idStory and idChapter to the useMutation hook without recreating the hook? is it normal to recreate the hook for each mutation call? Or I don't need to provide mutation keys? Will it overwrite the existing fetch?
Was this page helpful?