You are browsing as a guest. Sign up (or log in) to start making projects!

1h 10m 57s logged

Fixed a sneaky LocalStorage bug today! 🛠️

I initially put JSON.stringify directly inside useState, which completely crashed the app and prevented it from opening.
Rewrote the logic by moving JSON.stringify into a useEffect hook with tasks as a dependency. That got it working, but refreshing the page triggered a new bug: local storage was getting overwritten with an empty array.
I logged the data flow at every stage and caught the issue: useEffect was running on initial mount before state was restored. Added a simple length check (tasks.length > 0) before stringifying, and everything works perfectly now!
Always check your mount cycles! 🚀

0
9

Comments 0

No comments yet. Be the first!