Search code examples
javascriptreactjswebfrontendreactjs.net

React dynamics image


i'm learning the react techologie, i'm the first exercice i must put the images like this, but when i use the map function to put the images i don't saw the images :/

image dynamics example

import React from 'react'<br>
import './Style/App.css'


const tabImg = ['./img/html.png', './img/css.png', './img/javascript.png', './img/logo192.png']<br>
const displayImgTech = tabImg.map((tech) => <img key={tech} src={tech}  alt="techno"/>)<br>

export const Header = () => {
        return (
            <div className='container'>
                <img src={displayImgTech}  alt='technoFE'/>
            </div>
        )
}

Thank you


Solution

  • By passing displayImgTechin the src img props your are not adding an url but an "array" of img tags. so you just need to call {display take in your div like this:

    const displayImgTech = tabImg.map((tech) => <img key={tech} src={tech}  alt="techno"/>)<br>
    
    export const Header = () => {
            return (
                <div className='container'>
                   {displayImgTech} 
                </div>
            )
    }
    

    Edit modest-williamson-ibycr