javascript - TypeError:projects.map 不是函数(React)
问题描述
成分
const Pcards = ({ projects }) => {
return (
<div>
<CardColumns>
{projects.map((projects) => (
<Card>
<Card.Img variant="top" src={"http://localhost:8000" + projects.images[0].file_path + projects.images[0].file_name + projects.images[0].file_type} />
页面
class Projects extends Component {
state = {
projects:[]
}
componentDidMount() {
fetch('http://localhost:5000/api/projects')
.then(res => res.json())
.then((data) => {
this.setState({ projects: data })
})
.catch(console.log)
}
render () {
return (
<Pcards projects = {this.state.projects} />
);
}
}
新反应,此代码返回
TypeError:projects.map 不是函数
自从他编写了这段代码以来,这似乎在我的合作伙伴的一端编译得很好,我正在尝试扩展他的工作。
我看过其他类似的帖子,但找不到解决方法。知道这里发生了什么吗?
解决方案
尝试
class Projects extends Component {
constructor(props){
super(props)
this.state = {
projects:[]
}
}
推荐阅读
- c# - 是否可以根据解决方案配置引用程序集?
- php - Woocommerce - 如何在我的帐户区域的我自己的自定义页面上保留我自己的自定义表单?
- javascript - 从 URL 中提取顶级域
- c - 错误:函数 'rdtscl' [-Werror=implicit-function-declaration] 的隐式声明(但在旧内核版本上运行时没有错误)
- python - PyhtonAnywhere 超过 Flask 应用程序中的最大用户连接数
- ios - 用户是否可以使用 Key/Value 存储在 iCloud 中的数据?
- javascript - 如何解决,错误是“不变违规:文本字符串必须在
零件。” - vb.net - 在所述循环内更改循环的结束整数
- python - 调用 Endpoint.utilAddPendingJob(job) 时遇到问题
- java - 使用 faker.js 添加更多数据会生成 liquibase 错误