reactjs - map 不是一个函数,它可能是由于数组
问题描述
-
items.map() 不是一个函数,自从过去 5 个小时以来它一直困扰着我
class QuestionAPI extends Component {
constructor(props) {
console.log(props)
super(props);
this.state = {
items: [],
};
}
//Question answer api call
componentDidMount = () => {
axios.get(apiURL, {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ` + token,
},
}).then((result) => {
// console.log(result.data);
this.setState({items:result})
//error is hear
this.state.items.map((item) =>
//QuestionAPI container
this.props.QuestionApiHandler({ id: item.id }))
})
}
render() {
return (
<div>
</div>
);
};
}
export default QuestionAPI;
解决方案
- 我认为这可能有效
- 我希望它对你有帮助。
componentDidMount = () => {
axios.get(apiURL, {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ` + token,
},
}).then(response => response.data)
.then((data) => {
this.setState({ items: data })
this.state.items.map((item) =>
this.props.QuestionApiHandler({ id: item.id })
)
推荐阅读
- mysql - MySQL 将多个参数绑定到单个查询
- r - 如何确保作者拥有唯一的姓名
- python - 程序跳过 if 语句
- python - 在python中以特定字符开头和结尾的字符串中查找并打印子字符串的索引
- keycloak - Keycloak 无法使用有效令牌验证用户信息
- regex - 用 Notepad++ 中的正则表达式替换
- css - 有没有办法让 IMG 宽度:100%,边距 10px 自动适合固定宽度的 div 而不溢出
- java - 如何检查在 Spring Boot 项目(Intellij Idea)中的哪个位置使用了特定的 maven 依赖项?
- jquery - 如何使用 Animate 转到 Div
- python - 装饰器更改通用返回类型时的键入函数