【发布时间】:2017-06-19 15:19:12
【问题描述】:
我有两个组件。例如仪表板和卡片
仪表板:
render() {
const elements = this.props.cards.map((card, key) => {
return (
<Card item={card} onSave={this.onCardSave}>
)
})
}
卡片
render() {
return (
<div class="card">
<input type="checkbox" checked={this.state.item.checked} onChange={this.onChangeChecked} />
{ this.someCondition() && <input type="text" value={this.state.item.name} onChange={this.onChangeName} />}
</div>
)
}
因此文本字段的可见性取决于某些条件。例如:
function someCondition () {
return this.state.item.checked
}
!!此逻辑仅适用于 Card 实例
那么存储此逻辑的最佳位置在哪里?
在卡里面? (就像我的代码)
在仪表板内? (例如传递 props 中的所有事件)
如果你能提供一些关于这个主题的文章,我将非常感激
【问题讨论】:
-
this article 应该是很好的起点
标签: reactjs