Hamza Manan
Hamza Manan

Reputation: 420

cant access Api response in react js

see this Image

I cant access data object in the red circle (see image) but I can access it outside , please help as I cant understand what I am doing wrong?

Upvotes: 2

Views: 749

Answers (1)

Sathishkumar
Sathishkumar

Reputation: 3733

A simple example of a class component with state

export default class extends React.Component {

 constructor() { this.state = {data:[]}; }

 componentDidMount() {
  //Fetch data
  getTrendingVideo.then() { res => this.setState({data: res})}
 }

 render() { 
  console.log(this.state.data)
 } 
}

Upvotes: 2

Related Questions