I currently have a functional component table that takes two props, data which is an array of stock price data, such as: [{symbol:'TSLA',price:'420'},{symbol:'PLTR',price:'9000'}]
, and headers, which is simply a dynamically created array of all of the keys in the data, which would be [symbol,price]
for the data above.
As of now, I have a functioning table, however I am having issues maping the headers to each individual stock object. Here is the code I have now:
<TableBody>
{props.data.map((dataElement) => (
<TableRow key={dataElement.symbol}>
<TableCell align="left">{dataElement.symbol}</TableCell>
<TableCell align="left">{dataElement.price}</TableCell>
</TableRow>
))}
</TableBody>
but I would like to map each header to a tablecell that accesses the dataElement's properties for that header value. I was thinking it might be something like this, however THE FOLLOWING OBVIOUSLY DOES NOT WORK
<TableBody>
{props.data.map((dataElement) => (
<TableRow key={dataElement.symbol}>
{props.headers.map((header) => <TableCell>{dataElement.header}</TableCell>)}
</TableRow>
))}
</TableBody>
Does anyone know how I can achieve the functionality I am trying to achieve? Please let me know if clarification is needed.