DYNAMIC COMPONENT STYLING
STYLING COMPONENTS BASED ON SOME CONDITIONS.
GENERALLY, IN CSS WE CANNOT ADD STYLING TO COMPONENTS BASED ON SOME CONDITIONS.
HERE IN JSX STYLING CAN BE ADDED
NOTE: IN CSS WE DEFINE STYLING AS background-color:"red"
IN JSX WE DEFINE THEM IN CAMEL CASE backgroundColor:"red" (NO "-")
PRODUCT.JSX
function Product({ title, price, features }) {
let isDiscount = price > 15000;
let styles = { backgroundColor: isDiscount ? "blue" : "" };
return (
<div className="Product" style={styles}>
<h4>{title}</h4>
<h5>price:{price}</h5>
{isDiscount ? <p>Discount of 5%</p> : null}

Comments
Post a Comment