V
V
vovashaplin2020-06-13 21:07:14
React
vovashaplin, 2020-06-13 21:07:14

How convenient is it to accept images from the backend and put them on the site?

I get the image path relative to src using api, insert it into img, but it doesn't work
5ee5157bb26e5867610531.png

<img src={item.image} alt={item.name} className="card-img-top" />

I know that you can import pictures like this.
import Img from '../assets/player.jpg'
<img src={Img} alt={caseItem.title} />

But how to do this if I have a thousand products and pictures for them. Do not write me imports manually.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil Zinchenko, 2020-06-13
@danilzin

You need to accept images from the back, use a convenient method, such as REST API / GraphQL, and then save somewhere on the client (state/localstorage etc.) , let's say in an array of objects.
And there, display the list, the standard map method:

<ul>
  {list.map((item) => <li key={item.id}>{item.text}</li>)}
</ul>

Well, of course, you will have your own keys and names there, you can follow the example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question