私はReact JSの条件の束を扱うためにいくつかの面倒なコードを持っています。React JSのニュース記事レイアウトでRight Left Logicを処理する最良の方法は何ですか?
主に、ヒーローレイアウトとリストレイアウトがあるかどうかをテストし、イメージを左右どちらに配置するかをテストします。
これらをより小さいまたは別々のコンポーネントに分けることは許されませんでしたので、皆さんがこれらのすべての三項の代わりにこのロジックを処理するより良い方法があるのだろうかと思います。私はあなたが見るようにCol機能のためにReact Bootstrapも使用します。これらのタイプの状況に対処するためのより良い方法はありますか?私はちょうど私が適切なコードだと思ったものを置いた、うまくいけば十分です。ありがとう!
<div className={cellClassName}>
{layout === "hero" && thumbnailAlignment === "right" && showThumbnails && newsImage ?
<Col className="textContainer" md={6} sm={12}>
<ItemTextArea headline={headline}
previewText={previewText}
showDescription={showDescription}
showBylines={showBylines}
/>
</Col> : null}
{layout !== "hero" && thumbnailAlignment === "right" && showThumbnails && newsImage ?
<Col className="textContainer" md={10} sm={12}>
<ItemTextArea headline={headline}
previewText={previewText}
showDescription={showDescription}
showBylines={showBylines}
/>
</Col> : null}
{(thumbnailAlignment === "right" && !showThumbnails) || (thumbnailAlignment === "right" && !newsImage) ?
<Col className="textContainer" md={12} sm={12}>
<ItemTextArea headline={headline}
previewText={previewText}
showDescription={showDescription}
showBylines={showBylines}
/>
</Col> : null}
{layout !== "hero" && showThumbnails && newsImage ? <Col md={2} sm={12} className="Item-imageCell">
<div className={imageContainerClassName} style={customBackgroundStyles}>
{newsImage ? <img className="img-responsive" src={newsImage} alt={headline}/> : null}
</div>
</Col> : null}
{layout === "hero" && showThumbnails && newsImage ? <Col md={6} sm={12} className="Item-imageCell">
<div className={imageContainerClassName} style={customBackgroundStyles}>
{newsImage ? <img className="img-responsive" src={newsImage} alt={headline}/> : null}
</div>
</Col> : null}
{layout === "hero" && thumbnailAlignment === "left" && showThumbnails && newsImage ?
<Col className="textContainer" md={6} sm={12}>
<ItemTextArea headline={headline}
previewText={previewText}
showDescription={showDescription}
showBylines={showBylines}
/>
</Col> : null}
{layout !== "hero" && thumbnailAlignment === "left" && showThumbnails && newsImage ?
<Col className="textContainer" md={10} sm={12}>
<ItemTextArea headline={headline}
previewText={previewText}
showDescription={showDescription}
showBylines={showBylines}
/>
</Col> : null}
{(thumbnailAlignment === "left" && !showThumbnails) || (thumbnailAlignment === "left" && !newsImage) ?
<Col className="textContainer" md={12} sm={12}>
<ItemTextArea headline={headline}
previewText={previewText}
showDescription={showDescription}
showBylines={showBylines}
/>
</Col> : null}
</div>
ありがとう、これは役に立ちます!それは私には起こりませんでした。私は暗黙のうちに小道具を渡さなければならないので、コードを省略して、リストはそれよりも長かった。感謝します! – nyhunter77
これがあなたが探していたものなら、あなたは答えを受け入れてください。 –
ありがとう、Ashish! – nyhunter77