CodingNic

Persistence

Load Saved Tasks on Startup

Persistence 18 min read

Load Saved Tasks on Startup

Load Saved Tasks on Startup

Now the browser can store the board, but the application still needs to read that stored value when it starts.

Create a loading step that checks Local Storage for the same key used by saveTasks():

javascript
const savedTasks = localStorage.getItem("kanbanTasks");

If a value exists, turn the JSON string back into an array:

javascript
if (savedTasks) {
  tasks = JSON.parse(savedTasks);
}

Place this after the initial tasks declaration and before the first renderTasks() call. That way, the first render uses saved data when it exists.

Your startup flow should now be:

text
create default state
      ↓
check localStorage
      ↓
use saved state when available
      ↓
renderTasks()

Keep the existing sample tasks as the fallback for a first visit. A new browser with no kanbanTasks entry will still have something to display.

Checkpoint

Create or move a task, then refresh the page.

The board should come back with the same tasks and statuses. On a first visit, the sample tasks should still appear.