Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
Can't show an image in slider

I want to make a slider with several pics. so I'm using react. first I create Main component, where I put as a child Slider component. in Slider component where I created an array with an object, object has a path to the picture. then I create SliderContent component and import it in Slider component. then I created Slide component and import it in SliderContent component. here it is how looks Main component code:

import Slider from "../Components/Slider";



export default function Main(){

    return(
        <>
            <div className="main">
                <Slider />
            </div>
        </>
    )
}

here is how looks component Slider code:

import './Slider.css'
import SliderContent from "./SliderContent";
// import Slide from "./Slide";

const images = [
    {
        id: 2,
        title: "imageTwo",
        img: "../images/pharma.jpg"
    }
]

export default function Slider(){



    return(
        <>
            <div className="slider">
                <SliderContent slides ={images} />
            </div>
        </>
    )
}

here is how looks component SliderContent code:

import './Slider.css'
import Slide from "./Slide";


export default function SliderContent(props){
    return(
        <>
            <div className="sliderContent">
                {
                    props.slides.map(slide =>
                        <Slide key={slide.img} content={slide.img} />
                    )
                }
            </div>
        </>
    )
}

and here is how looks Slide component code:

import './Slider.css'

export default function Slide(props){
    return(
        <>
            <div className="slide" >
                <img alt="pic" src={props.content}/>
            </div>
        </>
    )
}

but here is what it shows: it shows an alt atribute of img tag in Slide component and picture doesn't open

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to require() your local images in order for them to show in React components, due to how Webpack bundles your app.

<img src={require('../images/pharma.jpg')} />

Another option would be to directly import the image:

import MyImage from '../images/pharma.jpg';

and then just use it where you need it:

<img src={MyImage} />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!