Design comparison
Solution retrospective
I couldn't solve how to save the previous shortened links. How can I do this?
Community feedback
- @ejim11Posted over 2 years ago
To make your data persist, you can use either localStorage or a backend like firebase. For local storage, after adding an data gotten from the api to the array that is used to display the shortened links, you can add the array to the localStorage.
//code localStorage.setItem("arrayName", array); this code above stores the array in the localStorage as a string. to get the array back, localStorage.getItem("arrayName");
the above code should be in a function that gets called every time the page loads. In the function, check whether there is anything stored and if there is, write a code that uses the data from localStorage to display the shortenedLinks. I know this is not concise but I hope it helps..
0 - @msunjiPosted over 2 years ago
If you're trying to save links you've shortened and you want this data to persist even after you've refreshed the page, you can use the localStorage property. It basically lets you save key/value pairs in the browser, and the data should persist even after you've refreshed the page or closed the tab/window. You can give it a try and see how it goes. Hope it helps!
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord