【发布时间】:2018-09-22 20:45:00
【问题描述】:
在我的主要组件 Game 中,它包含两个状态属性,即卡片数组 easyCards 和 hardCards,我渲染了两个 Button 组件。 Button 组件是展示性的,它们只是呈现传入的道具。我正在尝试根据我单击的按钮来确定,如何将两个卡片数组之一作为道具传递给 Card 组件以呈现它们?
handleEasyCards() {
}
handleHardCards() {
}
render() {
return (
<div>
<Timer />
<div>
<Button difficulty={this.state.easyButton} onClick={this.handleEasyCards}/>
<Button difficulty={this.state.hardButton} onClick={this.handleHardCards}/>
</div>
<Card cardTypes={ // I want to pass a specific state property here} />
</div>
);
}
}
这应该是onClick方法还是可以在render方法中处理的东西? Codesandbox
【问题讨论】:
标签: javascript reactjs