constructor(props) {
super(props);
this.state = {
inputAuthor: '',
inputText: '',
authorIsEmpty: true,
textIsEmpty: true
};
this.BtnClick = this.BtnClick.bind(this);
}
BtnClick(e) {
fetch('http://localhost:80/add-news', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'post',
mode: 'no-cors',
body: JSON.stringify(data)
})
.then(function (res) {
if (res) {
this.setState({
inputAuthor: '',
inputText: '',
authorIsEmpty: true,
textIsEmpty: true
});
} else {
console.log('Ответ сервера ' + res.status + ': ' + res.statusText);
}
})
.catch(function (res) {
console.log(res);
});
}
}
После успешного ответа от сервера, я пытаюсь изменить state, но получаю ошибку. Подскажите мне как это можно исправить?