Skip to content

Instantly share code, notes, and snippets.

@thoth-ky
Created April 29, 2020 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoth-ky/4f4b1500b784efbd16a4bce612b92a42 to your computer and use it in GitHub Desktop.
Save thoth-ky/4f4b1500b784efbd16a4bce612b92a42 to your computer and use it in GitHub Desktop.
React Table Component
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