I have a React Component that I am trying to display data in using the Object.keys() method and then trying to iterate through the data using .map().
Here is is how redux-logger is printing my data out:
body: {data: [0: {
attributes: {
name: "Text Widget Name",
category: "PreBuild",
description: "Text Widget Description",
"chart-type": "text_widget"
},
type: "widget-templates"
}]}
What I am trying to do is iterate through a number of these. Here is my react component.
import PropTypes from "prop-types";
import React from "react";
class TextWidget extends React.Component {
render() {
const {
data
} = this.props;
const textData = data;
const textWidgets = Object.keys(textData[0] || [])
.map(key => {
return (
<div key={key.id} className="tile-head">
<div className="title-head-content">
<h3>{key.attributes.name}</h3>
{key.attributes.description}
</div>
</div>
);
});
return (
<div
data={textData}
>
{textWidgets}
</div>
)
}
}
TextWidget.propTypes = {
data: PropTypes.array
};
export default TextWidget;
key.attributes.name is undefined.