Created
April 29, 2020 06:25
-
-
Save thoth-ky/4f4b1500b784efbd16a4bce612b92a42 to your computer and use it in GitHub Desktop.
React Table Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState } from 'react'; | |
import './App.css'; | |
const initialStuff =[[1,"a","b"], [2,"c","d"], [3,"e","f"]] | |
function App() { | |
const [stuff, setStuff] = useState(initialStuff) | |
const updateStuff = () => { | |
const newStuff = [[1,"a","b"], [2,"c","d"], [3,"new","new"]] | |
setStuff(newStuff) | |
} | |
return ( | |
<div className="App"> | |
<table> | |
<tr> | |
<th>ID</th> | |
<th>First Column</th> | |
<th>Second Column</th> | |
</tr> | |
{ | |
stuff.map(item => { | |
return ( | |
<tr key={item[0]}> | |
<td>{item[0]}</td> | |
<td>{item[1]}</td> | |
<td>{item[2]}</td> | |
</tr> | |
) | |
}) | |
} | |
</table> | |
<button onClick={updateStuff}>Update Table</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment