const [calculatedData, setCalculatedData] =useState("");
const calculateOrder = async() =>{
try{
const dataBody = `json=${encodeURIComponent(JSON.stringify(testInfo))}`;
const responseObj = await fetch('API', {
method: 'POST',
headers:{
'Content-Type': 'application/x-www-form-urlencoded',
},
body: dataBody
});
const res = await responseObj.json();
setCalculatedData(res);
console.log(res); // Perfectly display data
} catch(e){
console.log(e)
}
}
I am trying to save the response data to 'calculatedData', but I only get an empty string. Can anyone provide me any suggestion?
console.log(calculatedData) //Empty string