I got stuck with React fundamentals :/ There is code that generates table with json data inside:
import React from 'react'
import { DataTable } from 'react-data-components';
function buildTable(data) {
const tableColumns = [
{ title: 'Author', prop: 'author' },
{ title: 'Country', prop: 'country' },
{ title: 'Title', prop: 'title' },
];
return (
<DataTable
className="container"
keys="id"
columns={tableColumns}
initialData={data}
initialPageLength={5}
/>
);
}
let url = 'https://api.myjson.com/bins/1sbz3lp';
fetch(url)
.then(res => res.json())
.then((rows) => {
ReactDOM.render(buildTable(rows), document.getElementById('root'));
});
It gets the job done in index.js but is it possible to render table inside React component?
const Home = () => (
//renders buildTable(rows)
)
export default Home
Many thanks for all possible help, looking forward.
react-data-componentsfro table rendering