我刚开始看reactjs,并试图通过API来检索数据:如何设置状态以反应新数据?
constructor(){
super();
this.state = {data: false}
this.nextProps ={};
axios.get('https://jsonplaceholder.typicode.com/posts')
.then(response => {
nextProps= response;
});
}
当承诺回来我希望将数据分配到状态:
componentWillReceiveProps(nextProps){
this.setState({data: nextProps})
}
如何设置从api接收数据的新状态?目前状态没有设置?
jsbin裁判:https://jsbin.com/tizalu/edit?js,console,output
直接从诺言调用'setState'而不通过道具 – mguijarr