2

I'm trying to load an image from cache. It works whenever i switch between different tabs of the website, but when I reload the page, I get the default img icon instead of the actual image. Below is how I'm currently doing it. This is in reactJS

localStorage.setItem('image', URL.createObjectURL(imageFile));

setProfilePic(localStorage.getItem('image'))

What am I doing wrong?

cris
  • 265
  • 3
  • 11
  • https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL - *The URL lifetime is tied to the document in the window on which it was created*. Also, this way it's an URL, not a blob. – tevemadar Mar 15 '21 at 23:51
  • Does this answer your question? [How to save an image to localStorage and display it on the next page?](https://stackoverflow.com/questions/19183180/how-to-save-an-image-to-localstorage-and-display-it-on-the-next-page) – tevemadar Mar 15 '21 at 23:56

0 Answers0