Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
How to get an image link from a JSON to render in a react app

new to react here. As the title says, I have a JSON that has data in it that I am trying to render. Everything is showing except for the pictures. How can I make them show. Here is my code:

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;

The end result should be like this: https://i.imgur.com/FV4B6fg.png

about 4 years ago · Juan Pablo Isaza
4 Respostas
Responde à pergunta

0

You can use an img tag to render user avatar,

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

0

As you need to render the link as an image you should use img tag.

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

If you need to set width or height, you can do as follows.

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

0

You want to use img and {user.avatar} will return image url, so if you have a link of img, instead of directly using it in <td> tag use it like -

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

as you want to use img so you must need to use <img> tag .

about 4 years ago · Juan Pablo Isaza Relatório

0

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><img src={user.avatar} alt="text" /></td>

</tr> ) } </tbody> </table> </div> ); }export default App;

about 4 years ago · emss Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda