Passing ARRAYS TO PROPS

 ARRAYS CAN BE PASSED BY CREATING THEM INSIDE A FUNCTION SEPERATELY.

function ProductTab({}) {
  features=["hi-tech", "durable", "8gb ram"];

  return (

BUT , HERE WE DONOT PASS THEM LIKE THIS. INSTEAD WE PASS THEM DIRECTLY.

WE CAN ALSO PASS OBJECTS SIMILARLY.

HERE, FEATURES IS AN ARRAY AND OPTIONS IS AN OBJECT. OBJECTS CAN BE ACCESSED BY options.a

import Product from "./Product";

function ProductTab({}) {
 
  return (
    <>
      <Product
        title="phone"
        price={30000}
        features={["hi-tech", "durable", "8gb ram"]}
      />
      <Product
        title="laptop"
        price={50000}
        options={{ a: "basic", b: "advanced", c: "pro" }}
      />
      <Product title="pen" price={30} />
    </>
  );
}
export default ProductTab;


PRODUCT.JSX

import "./Product.css";
function Product({title,price,features,options}) {
  return (
    <div className="Product">
      <h4>{title}</h4>
      <h5>price:{price}</h5>
      <h5>{features}</h5>
    </div>
  );
}
export default Product;



Comments

Popular posts from this blog

DEPENDENCIES IN useEffect()

ACTIVITY1

CONDITIONALS