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

enter image description here

Mistake

enter image description here

Code

enter image description here

  • Apparently at the time of the first render, your query has not yet returned the result. - Ilya Paymushkin February
  • But the first level, for example, {this.state.reports.code} will return 200, which is true. - Ilya Rajewski

2 answers 2

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 }