Reputation: 264
I created an app that is a clone of flickr. As the user type in the input box it should render the pictures associated with the search value. Unfortunately, when I type it tells me "Cannot read property 'photo' of undefined", but then it kinda works. I really would like this app to work without any bugs. Please see attached the codesandbox.
https://codesandbox.io/s/condescending-kare-oqxw5
Upvotes: 0
Views: 53
Reputation: 7969
Make this function like this. First check weather photo
is present.
jsonp(flickrURL, flickrParams, { callback: "jsoncallback" }).then(
results => {
console.log(results);
if(results.photos){
const images = _(results.photos.photo).map(generateURL);
console.log(images);
this.setState({ images: images });
}
}
);
Upvotes: 1