我读了反应文件:https://reactjs.org/docs/state-and-lifecycle.html#state-updates-are-merged
代码在这里:
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})保留this.state.posts完整,但完全取代this.state.comments?为什么this.state.posts没有改变?