constructor(props) {
super(props);
this.state = {
posts: [],
comments: []
};
}
componentDidMount() {
fetchPosts().then(response => {
this.setState({
posts: response.posts
});
});
fetchComments().then(response => {
this.setState({
comments: response.comments
});
});
}
为什么 this.setState({comments}) leaves this.state.posts intact, but completely replaces this.state.comments?
为什么this.state.posts 会完整留下,而this.state.comments 会被覆盖?
谢谢大家。