【发布时间】:2018-02-08 23:59:25
【问题描述】:
我收到Uncaught TypeError: (0 , f.default) is not a function
items component
class Items extends React.Component{
constructor(props){
super(props);
this.state = {
itemList: [],
};
this.fetchItems = this.fetchItems.bind(this);
}
fetchItems(){
const url ="url" #api goes here;
this.setState({data: utilAPI(url)});
}
render(){
return(
<div className="jumbotron mx-auto jumbo-about">
{this.fetchItems()}
{console.log(this.state)}
<p>{this.state.itemList}</p>
</div>
);
}
}
export default Items;
item utils
export const fetchItemsAPI = (url) => {
fetch(url).then((res) => {
return res.json();
}).then(data=>{
return({
champion: data.id,
name:data.name
});
});
};
我不确定请求是否通过,因为 api 在我使用时有效。我不确定 util 请求是否良好,我不确定如何测试它。
【问题讨论】:
-
promise 不返回值,但其他 promise :)
标签: javascript reactjs api