CodingNic

Navigation and Persistence

Persist Favorites

Navigation and Persistence 30 min read

Persist Favorites

Persist Favorites

Open components/Favorites.js and the converter/page files that need to write favorite pairs.

Use localStorage to save the pair list:

javascript
const saved = JSON.parse(
  localStorage.getItem("fx-favorites") || "null"
);

Write the updated array whenever a favorite is added or removed.

Test it

Add favorite pairs, refresh the page, and confirm they remain.

Checkpoint

Favorites survive a page refresh without a backend.