async function postData(url, data) {
try{
const response = await fetch(url, {
method: 'POST',
mode: 'no-cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
'Content-Type': 'application/json',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'deflate, br',
'Connection': 'keep-alive',
'cache-control': 'max-age=0',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
body: JSON.stringify(data)
});
return await response.json();
}catch(e) {
console.log(e)
}
}
ну и как подсказали в комментах выше -убирайте или no-cors или response.json
this.state = {
countId: [
{id: 'id-1', quantity: 1},
{id: 'id-2', quantity: 5}
]
}
this.setState({
countId: {
...this.state.countId, countId: Object.assign({},{id:(event.currentTarget.id), quantity:1})
}
})