I have a data object that I need to be able to iterate over which is an array of objects. I'm attempting to do so with Object.keys, but missing something with my implementation, as I get the error TypeError: Cannot read property 'metrics' of undefined.
The data object is constructed as such:
export const data = {
metrics:
[
{
number:'10',
subText: 'content',
tertiary: 'more content'
},
{...}
]
}
where the component is trying to iterate over the object like so:
export const Metrics = (props) => {
return (
<div className="metric-container" aria-labelledby="metrics">
{Object.keys(props.data.metrics).map((metric, i) => (
<div className="metric"><h1>{metric.number}</h1><p>{metric.subText}</p><p>{metric.tertiary}</p></div>
))}
</div>
)
};
the data is imported into App.js with
import { data } from './assets/dataprops';
that has the component <Metrics {...data}/>