Creating a table when a button is clicked in Reactjs

1.2k views Asked by At

enter image description hereNeed to create a same new table with headings as shown above , when show button is clicked.it should create a table without the data but with the same headings The table should create each time when the show button is clicked .

1

There are 1 answers

0
vibhu On
 const[table,setTable] = useState([ <table>
<tr>
  <th>Heading 1</th>
  <th>Heading 2</th>
  <th>Heading 3</th>
</tr>
</table>])
const crteateNewTable = ()=>{
  setTable([...table,<table>
    <tr>
      <th>Heading 11</th>
      <th>Heading 22</th>
      <th>Heading 33</th>
    </tr>
    </table>])
}
 return (
<div className="App">
  {table}
<button onClick={crteateNewTable} style={{marginTop:"20px"}}> Create Table </button>
 </div>

hope this will help you with what you looking for