0

Why is my code not rendering the image that I am trying to render?

Any help is appreciated, I've been stuck with this problem for some time now.

Code:

export default class Homepage extends Component {
  constructor(props) {
    super(props)
    this.state = {
      images: [
        "https://www.clker.com/cliparts/3/m/v/Y/E/V/small-red-apple-hi.png",
      ]
    }
  }

  render() {
    return (
      <div>
        <div className="gallery">
          {this.state.images.map(({ src, index }) => (
            <img key={index} src={src} width="250px" height="250 px" />
          ))}
        </div>
      </div>
    )
  }
}

1 Answer 1

1

The issue is how you are using Array.map. If you remove the curly brackets it will work properly.

this.state.images.map((src, index) => (

For more details, check out the documentation on MDN.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh god... haha. I'm really tired it seems now. Thank you very much for the answer!

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.