【发布时间】:2016-10-06 03:12:12
【问题描述】:
我正在尝试添加一些样式,以便当我单击一个项目时它具有不同的背景颜色。
我有一个类 App,它导入类 ItemSection,它导入类 ItemList。在 ItemSection 和 ItemList 中,我的 propTypes 中都声明了 activeItem: React.PropTypes.object.isRequired。
我认为问题出在我的 App 的渲染方法上:
render(){
return(
<div className = 'app'>
<div className = 'manipulateItem'> {/*Need a better className*/}
<ItemSection
items = {this.state.items}
addItem = {this.addItem.bind(this)}
setItem = {this.setItem.bind(this)}
deleteItem = {this.deleteItem.bind(this)}
editItem = {this.editItem.bind(this)}
activeItem = {this.state.activeItem} /*THIS LINE I BELIEVE*/
/>
</div>
</div>
)
}
这是我的回溯:
bundle.js:1251 警告:失败的道具类型:必需的道具activeItem 未在ItemList 中指定。
在 ItemList 中(由 ItemSection 创建)
在 ItemSection 中(由 App 创建)
在 div 中(由 App 创建)
在 div 中(由 App 创建)
应用内
【问题讨论】:
-
这是来自ItemList,请您发布所有三个组件的代码。此外,您的问题最初是关于背景颜色,然后切换到 propType 警告。只是想了解您主要关心的是什么。