I'm trying to walk through an array and use its data but it was returning the error:
TypeError: Cannot read property 'forEach' of undefined
This is the result of the log:
class Restockers extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
...
}
}
render() {
const rows = [];
console.log('props: ', this.props); // this logs the content of props
this.props.restockers.restockers.forEach(...)
}
}
So when there is this.props.restockers.restockers in the code, in the log it is only this.props.restockers, which has an empty array.
Like in the next screenshot:
So I remove that extra restockers from the code. And now look at my error and my log:
I don't understand this weird behavior, now in the log it is this.props.restockers.restockers so the code is wrong because it is this.props.restokers.
How can this be solved?

