To add multiple rows to the table, you can create an array of objects to hold the data for each row.

Add multiple rows in the table using hooks in react js

To add multiple rows to the table, you can create an array of objects to hold the data for each row.

Share this article:

Share on Facebook Share on Twitter Share on LinkedIn Share on WhatsApp

See the Pen Untitled by Sikandar (@Pandit0503) on CodePen.

In this updated version, we create a rows state variable that holds an array of objects, and use the map function to loop over the array and generate a row for each object. When the "Add" button is clicked, we create a new object with the data from the form and add it to the rows array using the spread operator. We also reset the data state variable to clear the form fields.


Share this article:

Share on Facebook Share on Twitter Share on LinkedIn Share on WhatsApp