When I first started to render images in a React application, I remember being mystified about why an image might have to be required instead of imported like a component. Below are some examples of different ways of displaying an image on a page with explanations of what works and what does not.

For a more theoretical overview of what the require method does, you could start here:

What is require? | Node.js

Node.js follows the CommonJS module system, and the builtin require function is the easiest way to include modules that…

nodejs.org

Or to learn more about imports, you could go here:

import

The static import statement is used to import read only live bindings which are exported by another module. Imported…

developer.mozilla.org


Use Require

To use images in a React application, I start out by making a directory called Images in the src directory and then dragging and dropping image files from my computer into it. Then, when I want an image to appear in a particular place on the page, there are a few different options for getting it to show up.

#reactjs #programming #react #nodejs #javascript

How to Render Images in a React App
1.15 GEEK