【发布时间】:2017-05-21 08:36:04
【问题描述】:
我想将 inline 样式添加到 React 组件数组中,有人知道如何在不直接将高度添加到“ProductComponent”中的情况下最好地做到这一点吗?
组件有三个嵌套的 div 我只想为数组中的每个组件添加样式到父 div。我想在一个 ScrollableList 组件中执行此操作,该组件采用 ProductComponents 数组。我想在每个 ProductComponent 上添加“height:33%”。
我的“产品组件”。
class ProductComponent extends Component {
render() {
return (
<div
className="productContainer"
key={id}
>
<div className="imageContainer" >
<img src={ImageURL} role="presentation" />
</div>
<div className="productDetails">
<div className="productName"><strong>{Name}</strong></div>
<div className="productPrice">£ {Price}</div>
<div className="productBuyButton">
</div>
</div>
</div>
);
}
}
我有一个这些组件的数组,我在另一个 ScrollableList 组件中用作子组件。
render(){
const array = this.props.children
const children = array.map(ProductComponent => {
return(
add style 'height:33%' to the div productContainer
}
return(
<div>
{children}
</div>
)
}
【问题讨论】:
-
为什么要添加内联样式而不是仅仅添加一个具有与之关联的样式的类?
标签: arrays reactjs ecmascript-6 styles components