是否可以传递参数以将组件作为函数进行响应,我有要在子组件中使用的父组件,我想将子组件的值传递给父组件进行渲染
export default class CardComponent extends React.Component {
render() {
return (
<div>
<button type="button"> {this.props}</button>
</div>
);
}
}
import CardComponent from '../cardComponent/cardComponent'
export default class Events extends React.Component {
render() {
return (
<div>
<h1>Hello from events</h1>
<CardComponent name="name" />
<CardComponent name="location" />
<CardComponent name="description" />
...
</div>
)
}
}
答案 0 :(得分:0)
CardComponent this.props
中的错误应为this.props.name
export default class CardComponent extends React.Component {
render() {
return (
<div>
<button type="button"> {this.props.name}</button>
</div>
);
}
}