我在解决问题时遇到了这个问题,我无法真正解决这个问题:
我在包装器中有一个组件,该组件的状态由获取来更新。根据响应,组件显示出一些不同的东西。
但是,一旦请求完成,就会显示标题中的错误。当我<i className="fas fa-spinner fa-pulse"></i>用一个简单的字符串替换the时,问题就解决了。但是我想在那里渲染<i>标签(或者稍后再做其他事情)。这里有什么解决方案?并且该逻辑甚至应该放置在组件中还是应该放置在容器中?
容器:
class BookingContainer extends Component {
constructor(props) {
super(props);
this.state = {
booking : null
};
this.findBooking = this.findBooking.bind(this);
}
findBooking(bookingId) {
fetch('http://booking.local:8000/api/bookings/' + bookingId, {
method : 'GET',
headers : {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(
(response) => {
if (response.status !== 200) {
console.log('Error: ' + response.status);
return;
}
response.json().then ((data) => {
console.log(data.data);
this.setState({
booking : data.data
});
});
}
)
.catch( (err) => { …Run Code Online (Sandbox Code Playgroud)