Everytime i use fetch with async await it's blocking the js thread and it's frame drop to 1. here is my code:
export const apiCall = async (method, url, body) => {
const token = await getLocalToken();
const params = {
method: method.toUpperCase(),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
};
if (body) {
params.body = JSON.stringify(body);
}
if (token) {
params.headers.Authorization = `Bearer ${token}`;
}
const start = Moment();
const res = await fetch(`${apiUrl}${url}`, params);
let json = res;
try {
json = await res.json();
} catch (e) {
console.tron.log(e);
}
return json;
}
await
.JSON.stringify
is a CPU-bound operation, so if the JSON is huge, could be due to that. – JodhpurgetLocalToken
do? – Jodhpurfetch
that makes it synchronous, or some babel transform doing this? – Jodhpur