'Creating a table when a button is clicked in Reactjs
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 .
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vibhu |
