Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
Unable to display an image using React JS

I'm starting out with React JS with a code to display a picture, a header tag and an ordered list. Here's the JS code:

import React from 'react'
import ReactDOM from "react-dom"
const test = (
    <div>
        <img src="./balloons.png" width="100px" alt=""/>
        <h1>Names</h1>
        <ol>
            <li>A</li>
            <li>B</li>
            <li>C</li>
            <li>D</li>
        </ol>
    </div>
)

ReactDOM.render(test,document.getElementById("root"))

Here's the index.html part :

<html>
    <head>
        <link rel="stylesheet" href="index.css">
    </head>
    <body>
        <div id = "root"></div>
        <script src = "index.pack.js"></script>
    </body>
</html>

Now, the code runs and displays an output like this in the react app. I can't see the pic I uploaded.Output screen

Here is the folder arrangement in VS Code if it would help:

Folders

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

If you save the images in the public folder, it works fine

about 4 years ago · Juan Pablo Isaza Denunciar

0

try to import Image and use it in src like that:

import React from 'react'
import ReactDOM from "react-dom"
// try to import image
import YourImageUrl from './balloons.png';

const test = (
    <div>
        <img src="{YourImageUrl}" width="100px" alt=""/>
        <h1>Names</h1>
        <ol>
            <li>A</li>
            <li>B</li>
            <li>C</li>
            <li>D</li>
        </ol>
    </div>
)

ReactDOM.render(test,document.getElementById("root"))
about 4 years ago · Juan Pablo Isaza Denunciar

0

You will have import the image first. Write js code like this

import React from 'react'
import ReactDOM from "react-dom"
import balloons from './balloons.png'
const test = (
    <div>
        <img src={balloons} width="100px" alt=""/>
        <h1>Names</h1>
        <ol>
            <li>A</li>
            <li>B</li>
            <li>C</li>
            <li>D</li>
        </ol>
    </div>
)

ReactDOM.render(test,document.getElementById("root"))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda