how to load the images from the website dynamically in react

JavaScript
const images = require.context('../../public/images', true);

// adding dynamic paths
let dynamicImage = images(`./${someVariable}.png`);

// static image
let staticImage = images('./image.png');
Source

Also in JavaScript: