I am trying to make an image display component which takes an array of image src and displays the images in a layout like shown below. But the problem is that when I click I'm changing the src of the image element, it is fetching the image again.

How can I prevent the image from refetching again? The image must only be fetched on the first time. How can I achieve that?