0

I'm trying to display the images at I get from an api call. I'm getting:

Uncaught Error: Cannot find module '"https://i.ebayimg.com/thumbs/images/g/gw8AAOSwgsxagkvP/s-l225.jpg"'

Without require, I'm not getting a warning, but nothing is rendering.

console logging the pic variable below displays: "https://i.ebayimg.com/thumbs/images/g/gw8AAOSwgsxagkvP/s-l225.jpg"

I've read that I need to import the pics, but don't know how I should execute that.

class SingleItem extends Component {
constructor(props){
    super(props);
}
render(){
    const { image: imageUrl  } = this.props.value;
    let img = Object.values(imageUrl).toString()
    let pic = `"${img}"`
    var image = require(pic)
    return (
        <div>
            <div src={image}></div>
        </div>
    )
   }
 }

export default SingleItem;
3
  • You have a div rather than an img. Could that be the problem? Also, you won’t need require for absolute urls. Commented Jan 22, 2019 at 19:00
  • Jeez..<img> was it. Thanks Commented Jan 22, 2019 at 19:04
  • No problem. Happy it helped you out. Commented Jan 22, 2019 at 19:14

2 Answers 2

1

You don't need to require the image. Just set the imageUrl as the src attribute.

You also need to modify the div tag to an img tag.

The following should work great:

class SingleItem extends Component {
    constructor(props) {
        super(props);
    }
    render() {
        const { image: imageUrl } = this.props.value;
        let img = Object.values(imageUrl).toString()

        return ( 
            <div>
                <img src = {img}/> 
            </div>
        )
    }
}

export default SingleItem;
Sign up to request clarification or add additional context in comments.

Comments

1

Why are you requiring the image.

Just use the image url for the src attribute

render(){
    const { image: imageUrl  } = this.props.value;
    let img = Object.values(imageUrl).toString()
    return (
        <div>
            <img src={img}></img>
        </div>
    )
   }
 }

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.