【发布时间】:2019-12-11 03:38:41
【问题描述】:
我有一个看起来像这样的无状态功能子组件
const MultiChoiceQuestion = props => (
<div>
<h1>{props.questionText}</h1>
<button>{props.choice}</button>
</div>
)
我希望这个组件根据我父组件中的数组动态生成按钮。
class CNA extends Component {
constructor(props) {
super(props)
this.state = {
}
const choiceArray = ['1', '2', '3']
choiceArray.map(questionChoice => {
return questionChoice
})
}
render() {
return (
<React.Fragment>
<p>This is the cna survey</p>
<MultiChoiceQuestion questionText="Hello" choice={this.questionChoice} />
</React.Fragment>
)
}
所以基本上,因为我的选择数组中有 3 个项目,我想要生成 3 个按钮。有什么想法吗?
【问题讨论】:
标签: javascript reactjs oop ecmascript-6