how to render random images in create react app code example

Example 1: how to set diferent images in html through js

<div id="x"></div>

<script>
var img = document.createElement("img");
 
img.src = "image.png";
var src = document.getElementById("x");
 
src.appendChild(img);
</script>

Example 2: how to use text onclick to display images in javascript

$('img').click(function () { // on a click
  if($(this).attr('id') == '1') { // get the id attribute
    $('#div').html('Image with 1 was clicked'); // write the text
  } else { // else if
     // write something else for the 2
  }
}