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

267
Views
Cómo obtener un enlace de imagen de un JSON para renderizar en una aplicación de reacción

nuevo para reaccionar aquí. Como dice el título, tengo un JSON que contiene datos que estoy tratando de representar. Se muestra todo menos las fotos. ¿Cómo puedo hacer que se muestren? Aquí está mi código:

 import React, { useEffect, useState } from 'react'; import './App.css'; function App() { const [users, setUsers] = useState([]); useEffect(() => { fetch('https://reqres.in/api/users') .then(response => response.json()) .then(resData => setUsers(resData.data)) }, []); return ( <div className="App"> <table> <tbody> { users.map((user, index) => <tr key={index}> <td>{user.first_name}</td> <td>{user.last_name}</td> <td>{user.email}</td> <td>{user.avatar}</td> </tr> ) } </tbody> </table> </div> ); } export default App;

El resultado final debería ser así: https://i.imgur.com/FV4B6fg.png

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

0

Puede usar una etiqueta img para representar el avatar del usuario,

 <td> <img src={user.avatar} /> </td>
about 4 years ago · Juan Pablo Isaza Report

0

Como necesita representar el enlace como una imagen, debe usar la etiqueta img.

 <img src={user.avatar} alt=""/>

Si necesita establecer el ancho o la altura, puede hacer lo siguiente.

 <img src={user.avatar} alt="" width="200px"/>
about 4 years ago · Juan Pablo Isaza Report

0

Desea usar img y {user.avatar} devolverá la URL de la imagen, por lo que si tiene un enlace de img, en lugar de usarlo directamente en la etiqueta <td> , utilícelo como:

<td><img src={user.avatar} alt="text" /></td>

como desea usar img, debe usar la etiqueta <img> .

about 4 years ago · Juan Pablo Isaza Report

0

import React, { useEffect, useState } from 'react';

importar './Aplicación.css';


aplicación de función () {
const [usuarios, establecerUsuarios] = useState([]);
useEffect(() => { fetch(' https://reqres.in/api/users ') .then(response => response.json()) .then(resData => setUsers( resData.data ))}, []);
return ( <div className="App"> <table> <tbody> { users.map ((usuario, índice) => <tr key={index}> <td>{user.first_name}</td> <td >{usuario.apellido}</td> <td>{ usuario.email }</td> <td><img src={usuario.avatar} alt="texto" /></td>

</tr> ) } </tbody> </table> </div> ); }exportar aplicación predeterminada;

about 4 years ago · emss 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!