In the array, when accessing the first level, I get data without any problems.
When accessing the second level
I get TypeError error : Cannot read property 'yandex' of undefined
Array
Mistake
Code
In the array, when accessing the first level, I get data without any problems.
When accessing the second level
I get TypeError error : Cannot read property 'yandex' of undefined
Array
Mistake
Code
First, do not use componentWillMount , since this hook is not supported in new versions of React.
Second, add a check to your code:
<td>Запросы ({this.state.reports.positions && this.state.reports.positions.yandex && this.state.reports.positions.yandex.count}) Most likely you already have reports in the initial stack:
this.state = { reports: [] } and because of this, this.state.reports.code no error in this.state.reports.code , because there is simply undefined .
The problem was in the wrong property.
this.state = { user: [], reports: [] } Changed to
this.state = { user: null, reports: null } Source: https://ru.stackoverflow.com/questions/942433/
All Articles