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

341
Views
display image with strapi and react

I'm starting react with strapi and I can't display an image correctly.

My "animals" collection has an "image" field which is used to display an image.

However, I can't display the image (which is in upload)

In fact, I can't display the data that is in the image

Thanks to everyone who will help me

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


function AnimauxListe() {
    const [error, setError] = useState(null);
    const [Animaux, setAnimaux] = useState([]);
    const api_url = "http://localhost:1337/"
 
    useEffect(() => {
        axios
          .get('http://localhost:1337/api/animaux?populate=*')
          .then(({ data }) => setAnimaux(data.data))
          .catch((error) => setError(error))
      }, [])
    
      if (error) {
        // Print errors if any
        return <div>An error occured: {error.message}</div>;
      }
  return (
    <div className="App">
        <h2> Affichage des animaux présents dans la base de données</h2>
    <ul>
    {Animaux.map(animal =>
        <div key="animal.attributes.id" className="card" >  
        <img  src={animal.attributes.image.url}
          className="card-img-top" alt="raté"/>  
        <div className="card-body">  
        <h5 className="card-title">{animal.attributes.image.url}{animal.attributes.nom}</h5>
          <p className="card-text">{animal.attributes.Description}</p> 
          <p>{animal.attributes.image.url}</p>
           <a href="#" className="btn btn-primary">Voir {animal.attributes.nom}</a> 
            </div> </div>
    
    
    )}
    </ul>

    
  </div>
  )
}

On my code, I'm just trying to retrieve the url of the image for the moment but impossible. With all the updates I can't find a topic that matches my problem with a solution that fixes it. thank you

enter image description here

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

0

try to replace this line

const [Animaux, setAnimaux] = useState([]);

with this line

const [animaux, setAnimaux] = useState([]);
...
{animaux.map(animal => return (
       <div key="animal.attributes.id" className="card" >  
           <img  src={animal.attributes.image.url} className="card-img-top" alt="raté"/>  
           <div className="card-body">  
               <h5 className="card-title">{animal.attributes.image.url {animal.attributes.nom}</h5>
               <p className="card-text">{animal.attributes.Description}</p> 
               <p>{animal.attributes.image.url}</p>
               <a href="#" className="btn btn-primary">Voir {animal.attributes.nom}</a> 
           </div>
       </div>
)}
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!