I want to create a table header and add a button above the table which on click adds a new row to the table.
-
4Welcome to Stack Overflow. Go through this link for asking a better question stackoverflow.com/help/how-to-askAfnan Ashraf– Afnan Ashraf2020-01-16 09:55:03 +00:00Commented Jan 16, 2020 at 9:55
-
1This would help you : stackoverflow.com/questions/49171107/…Karan Mehta– Karan Mehta2020-01-16 09:57:35 +00:00Commented Jan 16, 2020 at 9:57
-
What have already tried? Where are you stuck?Mayank– Mayank2020-01-16 09:58:07 +00:00Commented Jan 16, 2020 at 9:58
-
2Language used in react native is react.js only so you can use that example to build yoursKaran Mehta– Karan Mehta2020-01-16 10:09:37 +00:00Commented Jan 16, 2020 at 10:09
-
1Here we don't write solutions to problems from scratch, but help those who are stuck while something (coding). Update your question with packages, snippets that you have tried and some error stack-trace that you encountered while trying themMayank– Mayank2020-01-16 10:10:48 +00:00Commented Jan 16, 2020 at 10:10
|
Show 2 more comments
1 Answer
Just see the example below
import React, {useState} from "react";
import "./styles.css";
export default function App() {
const [rows,setRows] = useState([])
return (
<div className="App">
<h1>Header</h1>
<div>
{rows.map((item)=>(<div><h1>{item.number}</h1></div>))}
</div>
<button onClick={()=>setRows([...rows,{number:rows.length}])}>Add Row</button>
</div>
);
}
2 Comments
Bhargavi reddy
Thanks for this.. but still am not able to add a new row on clicking button
user321
@Bhargavireddy have you found any solution yet?