-1

I want to create a table header and add a button above the table which on click adds a new row to the table.

7
  • 4
    Welcome to Stack Overflow. Go through this link for asking a better question stackoverflow.com/help/how-to-ask Commented Jan 16, 2020 at 9:55
  • 1
    This would help you : stackoverflow.com/questions/49171107/… Commented Jan 16, 2020 at 9:57
  • What have already tried? Where are you stuck? Commented Jan 16, 2020 at 9:58
  • 2
    Language used in react native is react.js only so you can use that example to build yours Commented Jan 16, 2020 at 10:09
  • 1
    Here 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 them Commented Jan 16, 2020 at 10:10

1 Answer 1

1

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>
 );
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for this.. but still am not able to add a new row on clicking button
@Bhargavireddy have you found any solution yet?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.