@arnoldo.moen
To create a table in React.js, you can follow these steps:
- Create a new React component for the table. You can do this by creating a new JavaScript file and importing the necessary React modules.
import React from 'react';
function Table() {
return ;
}
export default Table;
- Inside the component's render method, define the table structure using HTML markup. Use the table, thead, tbody, and tr elements to create the structure of the table.
function Table() {
return (
{/* Add more rows here */}
);
}
- You can use JavaScript arrays to dynamically populate the table. Map over the array to create multiple rows with different data.
function Table() {
const data = [
{ id: 1, col1: 'Data 1', col2: 'Data 2', col3: 'Data 3' },
// Add more data objects here
];
return (
{data.map((row) => (
))}
);
}
- Finally, export the Table component.
export default Table;
You can now use the table component in other React components by importing and including it in their render methods.