In this episode, we focus on making our note app way more useful by making sure your notes actually stick around after you refresh the browser. Right now, whenever you reload the page, all your notes disappear and you’re back to square one. Definitely not ideal for any real app!
The solution: we use the browser's local storage as a quick way to save and retrieve your notes. We walk through how to persist notes to local storage every time you update or create a note, and how to initialize your app with the saved notes when the page loads again. There's some discussion about best practices—like when to actually save the notes (on creation, when editing, etc.), and the difference between storing all notes together vs. updating them individually if you were using a real database.
You'll see a step-by-step implementation: saving the notes as a string to local storage (using JSON.stringify
), then making sure to JSON.parse
them when loading up your app. We even debug a few little mistakes—like forgetting to parse JSON or always starting from an empty array—so you’ll know the gotchas, too.
By the end, we have a notes app that keeps everything in sync with local storage; your notes stay exactly as you left them, even after a refresh!