localStorage so they survive page refreshes and browser restarts. The /favs route shows a dedicated view with only the favorited coins and an individual price chart for each one.
How to add a favorite
EveryCryptoCard row includes a star icon button in the rightmost column. Clicking it toggles the coin’s favorited state:
- Empty star — the coin is not favorited
- Yellow filled star — the coin is favorited
useFavorites hook
Favorites state is managed by theuseFavorites hook in src/hooks/useFavorites.jsx. The hook initializes from localStorage on first render and writes back to localStorage any time the list changes:
useFavorites.jsx
Returned values
Array of CoinGecko coin IDs that are currently favorited (e.g.
["bitcoin", "solana"]).Appends a coin ID to the favorites list and persists it to
localStorage.Removes a coin ID from the favorites list and updates
localStorage.Returns
true if the given coin ID is in the favorites list.localStorage persistence
Favorites are stored under the key"cryptoFavorites" as a JSON-serialized array of coin ID strings:
useState reads from localStorage synchronously on mount, so the favorites list is always populated before the first render. If localStorage is unavailable or the stored value is corrupted the hook silently falls back to an empty array.
Favorites are scoped to the browser. They are not synced across devices or user accounts.
Favorites page (/favs)
The Favorites page at /favs loads the full top-20 coin data via keepInfo() and then filters it down to only the favorited coins:
favorites.jsx
favorites array changes, so adding or removing a favorite from the listing page is reflected immediately if the user is already on /favs.
For each favorited coin the page renders:
- A
CryptoCardrow in the same table format as the home page - An
AreaChartFillByValuechart locked to that coin’s ID, showing its price history