RENDERING ARRAYS

 ARRAYS CAN BE RENDERED IN TWO WAYS:

1. SENDING ARRAY OF ELEMENTS

2. BY MAPPING 


1.

function ProductTab() {
  let features = [<li>hi-tech </li>, <li>durable</li>, <li>8gb ram</li>];

  return (
    <>
      <Product title="phone" price={30000} features={features} />

2.

      <p>{features.map((feature) => <li>{feature}</li>)}</p>


PRODUCTTAB.JSX

import Product from "./Product";

function ProductTab() {
let options=["8gb ram","24mp cam","33w"];
  return (
    <>
      <Product title="phone" price={30000} features={options} />
      {/* <Product title="laptop" price={50000} />
      <Product title="pen" price={30} /> */}
    </>
  );
}
export default ProductTab;

PRODUCT.JSX

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







Comments

Popular posts from this blog

DEPENDENCIES IN useEffect()

ACTIVITY1

CONDITIONALS