私はReactJSを初めて使っています。 ProductInfoは、ユーザーが情報を記入できるプロジェクト内のカードです。 ReactJSコードのProduct const内に条件を設定したい:レンダリングされたアイテムの数に応じて、特定のブートストラップクラスの条件でreactJS?
ここで2つのProductInfoカードしか記入されていない場合は、class-nameにcol-md-6を適用して2枚のカードが2つ以上のProductInfoカードが記入されている場合は、col-md-4を使用してください。これをどうやってやりますか?
const ProductInfo = ({ title, blurb }) => (
<div>
{title && <h3 className="color-accent">{title}</h3>}
{blurb &&
<span dangerouslySetInnerHTML={{__html: productBlurb}} />
}
</div>
);
const Product = (props) => (
//If only two ProductInfo cards are present, apply a boostrap class of col-md-6, otherwise apply the bootstrap class below
<div className="hs-product col-xs-12 col-sm-12 col-md-4" >
{props.productIconLink ?
<a href={props.link} target="_blank">
<ProductInfo {...props} />
</a>
:
<ProductInfo {...props} />
}
</div>
);