I\'ve tried to use fetch to call from backend using react, without libs (such as Axios). So I created this function:
export function api(url, method, body, i
For me, the error occurred because I included a "body" on a GET request when calling fetch(). Excluding the body for GET requests solved the problem (e.g., if you're writing a generic function or framework that handles different HTTP request types). Here's a simple code excerpt to illustrate the solution (obviously this code would need expansion in the real world, but it makes the point):
// Earlier code that specifies the HTTP method
let method = 'GET';
// Create fetch() init object
let fetchInit = {};
if (method !== 'GET') {
fetchInit.body = yourRequestBody;
}
// Start network request
fetch(url, fetchInit).then...