productCadr.js
μ½λ μμ μ
{item.stock === 0 ? (
<button disabled type="button">
Out of stock
</button>
) : typeof item.displayPrice === 'string' ? (
<button type="button">Select</button>
) : (
<button type="button">Add</button>
)}
μ½λ μμ ν β¨
{item.stock === 0 ? (
<button disabled type="button">
Out of stock
</button>
) : (
<button type="button">
{typeof item.displayPrice === 'string' ? 'Select' : 'Add'}
</button>
)}
productCadr.js
item.stock
κ³Ό item.displayPrice
μ κ΄ν΄ 쑰건μ λ°μ§λ λ‘μ§μ mapν¨μ μμμ return μ μ λ€λ‘ μμ±ν΄μ μ‘°κ±΄λΆ λ λλ§μΌλ‘ ꡬνν΄λ³΄κΈ°!!!μ½λ μμ μ
{cardInfo.item.map(item => {
return (
<div
className="productCard"
key={item.id}
onClick={() => console.log(item)}
>
<div className="productCard__header">
{item.isNew && <span className="new">NEW</span>}
<img src={item.imageUrl} alt="product image" />
<div className="symbols">
{item.symbolUrl.map(symbolSrc => {
return <img src={symbolSrc} alt="" />;
})}
</div>
</div>
<div className="productCard__text-block">
<h2>{item.displayTitle}</h2>
<p>{item.subtitle}</p>
<ul>
{item.description.map(text => {
return <li>{text}</li>;
})}
</ul>
</div>
<div className="productCard__bottom">
<p>${item.displayPrice}</p>
{item.stock === 0 ? (
<button disabled type="button">
Out of stock
</button>
) : (
<button type="button">
{typeof item.displayPrice === 'string' ? 'Select' : 'Add'}
</button>
)}
</div>
</div>
);
})}
μ½λ μμ ν β¨
β π€ μ΄λ κ² νλκ² λ§λμ§ μ λͺ¨λ₯΄κ² λ€ γ
γ
{cardInfo.item.map(item => {
const outOfStock = item.stock === 0;
const isPriceTypeString = typeof item.displayPrice === 'string';
return (
<div
className="productCard"
key={item.id}
onClick={() => console.log(item)}
>
<div className="productCard__header">
{item.isNew && <span className="new">NEW</span>}
<img src={item.imageUrl} alt="product image" />
<div className="symbols">
{item.symbolUrl.map(symbolSrc => {
return <img src={symbolSrc} alt="" />;
})}
</div>
</div>
<div className="productCard__text-block">
<h2>{item.displayTitle}</h2>
<p>{item.subtitle}</p>
<ul>
{item.description.map(text => {
return <li>{text}</li>;
})}
</ul>
</div>
<div className="productCard__bottom">
<p>${item.displayPrice}</p>
{outOfStock ? (
<button disabled type="button">
Out of stock
</button>
) : (
<button type="button">
{isPriceTypeString ? 'Select' : 'Add'}
</button>
)}
</div>
</div>
);
})}
productCadr.js
μ½λ μμ μ
if (selectedCategory === 'category') {
return (
<div className="productCardsGroup">
<h1>Vitamins</h1>
{productDatas.map(cardInfo => {
return <ProductCards cardInfo={cardInfo} />;
})}
<h1>Powders</h1>
{powderDatas.map(cardInfo => {
return <ProductCards cardInfo={cardInfo} />;
})}
</div>
);
} else {
return (
<div className="productCardsGroup">
<h1>Eyes</h1>
{powderDatas.map(cardInfo => {
return <ProductCards cardInfo={cardInfo} />;
})}
</div>
);
}