I dont understand a syntax difference between vanilla javascript and ES6 in a React Application. My first code that doesn't work is
class App extends Component{
constructor(props){
super(props);
this.state = {videos:[]};
YTSearch({key: API_KEY,term :'surfboards'},function(videos){
this.setState({videos : videos});
});
}
This gives a 'Cannot read property 'setState' of undefined' error in the console
but changing the syntax to
YTSearch({key: API_KEY,term :'surfboards'},(videos)=>{
this.setState({videos : videos});
});
fixes the problem. Isn't both the same thing(I may be wrong).Using
function(videos){}
and
(videos) => {}
I am not comfortable with javascript so any help is appreciated.