0

React doesnt return img in document from list-src

import React from 'react'

export default function dio() {

var storys = [
    {
        src: './images/profilna.jpg'
    },
    {
        src: './images/profilna.jpg'
    },
]

return (<div>
    <div >
        <img src="./images/profilna.jpg" alt=""/>
        {
            storys.forEach(story => {
            //this dont return img in document
           return( <img src={story.src} />
  )
            })

        }
    </div>
</div>
)

}

1
  • 3
    Have you tried using .map? Commented Mar 23, 2021 at 20:32

1 Answer 1

2

The method .forEach() has no return, try with .map()

export default function dio() {

var storys = [
    {
        src: './images/profilna.jpg'
    },
    {
        src: './images/profilna.jpg'
    },
]

return (<div>
    <div >
        <img src="./images/profilna.jpg" alt=""/>
        {
            storys.map(story => {
              return( <img src={story.src} />
                )
            })

        }
    </div>
</div>
)
}
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.