0

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

4
  • 1
    const images = _(results).map(generateURL); this will solve your problem Commented Mar 3, 2020 at 7:59
  • @Manish hey Manish, thanks I will defo try it out! Do you know by any chance why if I type in my input and console log it always shows me a result with one character less? If I type money in my console.log will appear mone Commented Mar 3, 2020 at 8:06
  • 1
    You are passing this.state.query to the parent even before state.query is set to the actual value. setState sets the state at later point of time. so try calling this.props.onInput(event.target.value); Commented Mar 3, 2020 at 8:14
  • @ArpithaChandrashekara omg yes! thanks! I hope one day it will become a second nature for me :) Commented Mar 3, 2020 at 8:18

1 Answer 1

1

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 });
      }
  }
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.