-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
I would like to reuse my fetch function inside useMutation hook in different places in my react app. Each fetch function has different url endpoints and data. While I can pass data inside mutate function, how do I pass other parameters like url, http methods ?
I tried passing url parameter, I am getting
index.js:1 SyntaxError: Unexpected token W in JSON at position 0
My fetch function is as follows
const postPhone = async (data, url) => {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data)
};
const response = await fetch(
permanentUrl + url ,
requestOptions
);
const otpResponse = await response.json();
return otpResponse;
}
If I have to use a static url inside the function with no url parameter then mutate function of useMutation is working absolutely fine. But then I have to write multiple postPhone function many times. Is there any solution for this?
mweel1
Metadata
Metadata
Assignees
Labels
No labels