Reactjs 初学入坑 - 报错 TypeError: Cannot read property ‘map‘ of undefined

### 由于按照视频中的代码写法运行的时候,导致报错:React TypeError: Cannot read property 'map' of undefined 

Reactjs 初学入坑 - 报错 TypeError: Cannot read property ‘map‘ of undefined

 

因为自己修改了视频中的Api,导致了数据返回不一样,返回的json中没有results字段,导致赋值命名 .then(({results: items}) => this.setState({ items })) 这行代码有问题,使 this.state.items 一直赋值失败,所以会报错。

 

解决?

》这里需要修改下赋值代码: .then(results => this.setState({ items: results })) 

或如果我们让参数名和key值保持一致,可简写为: .then(items => this.setState({ items }))