list rendering in react

 import { useEffect, useState } from "react";


function App() {


  const [product, setProduct] = useState();


  useEffect(() => {

    fetch('https://dummyjson.com/products')

      .then(res => res.json())

      .then(data => {

        console.log(data.products);

        setProduct(data.products);

      });

  }, []);


  return (

    <>

      <h3>Main App</h3>

      <br></br>

      <br></br>


      <table>

        <tr>

          <th>Title</th>

          <th>Description</th>

          <th>Price</th>

        </tr>

        <tbody>

          {

            (product && product?.length) && (product.map((product,index)=>(

          <tr key={index}>

            <td>{product.title}</td>

            <td>{product.description}</td>

            <td>{product.price}</td>

          </tr>

          )))

        }

        </tbody>

      </table>


    </>

  );

}


export default App;


Popular posts from this blog

MCSL 216 MCA NEW Practical ~ common questions suggestions

dev chaeatsheet

STRAPI