All Posts In Hook

Building a Robust useFavorites Hook (and the bugs we fixed)
Adam C. |
We built a unified useFavorites hook to handle both local and verified users: logged-out or unverified users store up to 50 favorites in localStorage (with cross-tab sync), while verified users get 200 favorites synced to the database with optimistic add/remove. Early versions had problems with infinite re-renders and over-complicated refs, but the fix was simple—limit the fetch effect to userSub changes and add a lightweight alive guard. The final hook is clean, predictable, and keeps UI updates instant while background queues handle persistence.