Skip to content
Advertisement

Setting localStorage using fetch

I am creating a weather dashboard and am trying to save the city name to local storage. I already have the logic written to have the city post in the history section I just can’t get the data to stay there after I reload the page. I have checked and it is saving to local storage but just not retrieving it. Here is the fetch call and the code underneath where I am trying to save the localStorage:

JavaScript

Advertisement

Answer

To retrieve your persisted stringified JSON data, you want to do this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement