我被困住了,不知道这里发生了什么:
这是子组件的代码:
import React, { Component } from "react";
import { ErrorBoundary } from "../../utils/ErrorBoundary";
class FrontCard extends Component {
render() {
return (
<div>
{console.log(this.props)}{" "}
{this.props.map((card, index) => (
<Card key={index} style={{ width: "18rem" }}>
<Card.Img variant="top" src="holder.js/100px180" />
<Card.Body>
<Card.Title>{card.title}</Card.Title>
<Card.Text>{card.body} </Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
))}
</div>
);
}
}
export default FrontCard;
这就是它的名字:
<FrontCard {...this.state.cards} />
如您所见,我在映射之前记录了 props,并且该数组位于控制台中:
{0: {…}, 1: {…}, 2: {…}}
问题是,为什么说 map 不是函数?
Uncaught TypeError: this.props.map is not a function
at FrontCard.render (FrontCard.jsx:44)