import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
import videoDetails from './components/listvideos';
class YoutubeApp extends Component {
constructor(props){
super(props)
this.state = {
videos:[]
};
this.apiCall('surfing');
}
apiCall(term){
const params = {
part: 'snippet',
key:APP_KEY,
q:term,
type: 'video'
};
axios.get(APP_URL, { params: params})
.then(function(response) {
this.setState({
videos:response
})
})
.catch(function(error) {
console.error(error);
});
}
render(){
return (
<div>
<videoDetails/>
</div>
)
}
}
ReactDOM.render(
<YoutubeApp/>,
document.getElementById('app')
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react-dom.min.js"></script>
<div id="app">
</div>
Hi I am trying to make a youtube clone for practice I am a beginner on this but i cannot see why the state on react is giving me a problem I am trying to set the state to my videos array so i can pass it to other components I didn't include the api key or url but is very readable by the way this is the error {Cannot read property 'setState' of undefined}