score:5
It is better to provide what have you tried up to now and where you got stuck. In SO, if you don't provide that information your question probably will be closed. But, here is a welcome present: You can use JS expressions in JSX, how good. So, as @Roy Scheffers suggested you can use map to do create tables or anything you want.
const data = [
{ name: "Video1", text: "video 1 text" },
{ name: "Video2", text: "video 2 text" },
{ name: "Video3", text: "video 3 text" },
];
const App = () => (
<div>
<table>
{data.map(el => (
<tr>
<td>{el.name}</td>
<td>{el.text}</td>
</tr>
))}
</table>
</div>
);
ReactDOM.render(<App />, document.getElementById("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>
This example is just for fun:
class App extends React.Component {
state = {
data: [
{ name: "Video1", text: "video 1 text" },
{ name: "Video2", text: "video 2 text" },
{ name: "Video3", text: "video 3 text" },
],
count: 1,
};
updateTable = () => {
this.setState(prevState => ({
data: [...prevState.data, { name: `foo${prevState.count}`, text: `bar${prevState.count}` }],
count: prevState.count += 1,
}))
if (this.state.data.length > 5) { clearInterval(this.intervalId); }
}
componentDidMount() {
this.intervalId = setInterval(this.updateTable, 1000);
}
componentWillUnmount() {
clearInterval(this.intervalId);
}
render() {
return (
<div>
<table border="1">
{this.state.data.map(el => (
<tr>
<td>{el.name}</td>
<td>{el.text}</td>
</tr>
))}
</table>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>
score:0
There are some great React npm projects out there as well that can do this for you and give you a lot of flexibility. I found this one https://github.com/agracio/ts-react-json-table and it looks really cool. I haven't used it just yet, but I am about to, as I was searching for something to take JSON and make a table quickly.
Source: stackoverflow.com
Related Query
- How to make a react table whose rows and columns come from a JSON object
- How to make some columns align left and some column align center in React Table - React
- How to use drag and drop functionality both columns and rows in my React Table - ReactJS
- How to make a list from json object using React
- How to make some columns fixed and some columns draggable in React Table - ReactJS
- How to fetch Json nested and Make it Array of object in React
- How to parse a JSON object from an external file in React using .map() in ES6 and a loop?
- how to loop throgh array of object from axios json respone in react js and set them in div?
- How do I create a table from a JSON object in React JS?
- How do I wrap a React component that returns multiple table rows and avoid the "<tr> cannot appear as a child of <div>" error?
- How to make the API call and display it in React JS using React Table and Axios?
- How to make a React component look more readable and clean from my example?
- Creating a table that can drag and drop both columns and rows on React
- How to make my component re render after updating props from selector in react and redux-saga?
- How to fetch and display data from json file in react typscript
- How to make react data grid table cell editable and focused on click of a button without performing a double click action
- How do I correctly add data from multiple endpoints called inside useEffect to the state object using React Hooks and Context API?
- How to filter JSON data from API and setState in React
- Where does the root reducer come from in this redux react example and how does dispatch knows which reducer to go?
- How to find most recent date from an array of object then add new field and return array in react
- How to make a column as clickable in a react bootstrap table and avoid showing it as text field in "Add Row"?
- How do I obtain a value from JSON object in a React render function?
- How to map over 2 Array of object in React and render to Table
- How can I format an excel file with empty rows to have nested arrays and match a JSON object that I need to render?
- How to get nested Object from JSON File using React JS
- Not able to set the JSON object of Arrays in React js using axios.get function and display the object of Arrays in table
- How to position columns at the left and data at the right of material UI table for React
- How to hide a column on REACT Material table in all rows and show it on Edit for the Particular Row I am editing and Add Operations on new row adding?
- How to correctly type a null value in typescript react app, retrieved from an JSON object (api call) when using Object.entries to retrieve the value?
- How can I iterate through JSON arrays and show data in a table in React
More Query from same tag
- Problem on Dropdown Broken layout in ReactJS
- I have an import export error in react-redux boiler plate
- Why isn't child component rendering when testing with React Testing Library?
- Use Buttons to trigger filter function on react-table in React
- Default value for prop
- How to use React Test Utilities with Jasmine
- TypeError: language.map is not a function when getting data using axios
- What is the proper typescript type for creating element
- VSCode autoimport not working after using absolute imports in NextJS
- React TypeScript: How to spread in other values of a nested state object
- Why aren't these two versions of a higher order function giving the same results?
- why is this.state.records.amount undefined?
- Semantic-ui-react library does not work; no errors
- how to set a react js header title to an element of an array?
- Mention list and emoji top position (Draft.js)
- Pass Props and Access Object Values in ReactJS
- Material UI React Slider Component Not Working on mobile
- Passing in an array of strings with unique variable names associated
- TypeError: this.state.persons.map is not a function while using axios.get in React
- How can detect that should update a property of previous object?
- Django-React authentication: limit users who can obtain simpleJWT tokens
- How to make code changes show when using yalc
- useEffect running on every render even when dependency is unchanged
- Why can't this Spring Boot application find the main page?
- Changing Context Menu in React Based on Selected Component
- Animation libraries like Splitting.js and anime.js not working on React JS
- How to let react only render part of the component?
- Pass data between independent component using flux react
- How i can change the state of my button on my object?
- Eslint doesnt see React components in use