I currently want to show the table header according to the API Attributes which will show weight, length, width, and hook, I have tried but I stuck in the part how to display only the Attribute object as below image. Plz, help to teach me this. This is the result I get , but I just wanted to show the Attributes object as header .
const renderTableHeader = () => {
const header = Object.keys(data.data.VariationList[0]);
return header.map((key, index) => <th key={index}>{key.toUpperCase()}</th>)
}
return (
<Table>
<thead>
<tr>{renderTableHeader()}</tr>
</thead>
<tbody>
{data.data.VariationList.map((variation) => (
<tr key={variation.VariationSKU}>
<td className="text-center">{variation.VariationSKU}</td>
<td>{variation.Attribute.Weight}</td>
{variation.Attribute.Diameter ? (
<td>{variation.Attribute.Diameter}</td>
) : null}
{variation.Attribute.Length ? (
<td>{variation.Attribute.Length}</td>
) : null}
{variation.Attribute.Size ? (
<td>{variation.Attribute.Size}</td>
) : null}
{variation.Attribute.Width ? (
<td>{variation.Attribute.Width}</td>
) : null}
{variation.Attribute.Hook ? (
<td>{variation.Attribute.Hook}</td>
) : null}
<td className="text-right">{variation.Price}</td>
<td className="td-actions text-right">
<Button
className="btn "
color="danger"
data-toggle="tooltip"
id="tooltip542628903"
size="md"
type="button"
onClick={() =>
addToCart(data.data.ID, variation.VariationSKU)
}
>
ADD TO CART
</Button>
</td>
</tr>
))}
</tbody>
</Table>
)
