I'd be grateful if you could help me with my problem.
I've written a component to demonstrate the information of an array which includes both index.js and TableData.js files.
Transferring the information of array from index.js to TableData.js in order to demonstrating them, I've faced an ambiguous error.
What's the problem with my code? In which part have I made a mistake?
index.js
import React from "react";
import ReactDOM from "react-dom";
import TableData from "./TableData";
const LP = [
{ id: 11, name: "CD", price: "2000", describe: "Educational" },
{ id: 24, name: "Pen", price: "3500", describe: "Design" },
{ id: 83, name: "Pencil", price: "2500", describe: "Design" }
];
ReactDOM.render(<TableData rows={LP} />, document.getElementById("root"));
TableData.js
import React, {component} from 'react';
import {makeStyles} from '@material-ui/core/styles';
import {
Table,
TableBody,
TableCell,
TableHead,
TableRow
} from '@material-ui/core';
//****** Style CSS ******
const useStyles = makeStyles({
root: {
width: '100%',
overflowX: 'auto'
},
table: {
minWidth: 650
}
});
const classes = useStyles();
const test = 'right';
//****** Class List Product ******
class TableData extends component{
state = {
items: this.props,
}
render() {
return (
<Table className={classes.table} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Name Product</TableCell>
<TableCell align="right">Price</TableCell>
<TableCell align="right">Describe</TableCell>
</TableRow>
</TableHead>
<TableBody>
{items.map((item, index) => (
<TableRow key={item.id}>
<TableCell component="th" scope="row">
{item.name}
</TableCell>
<TableCell align={test} data={item.name}>{item.price}</TableCell>
<TableCell align="right">{item.describe}</TableCell>
<TableCell align="right">
<button>
DEL
</button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
}
export
default
TableData