#Trouble with localStorage and useEffect() resetting variables

14 messages · Page 1 of 1 (latest)

formal vapor
#

I've been working on implementing the We Are the Champions solo project in React and have gotten everything working properly except for an issue I'm having with localStorage and useEffect. The app is keeping track of endorsements input the user using a firebase realtime database that sets state. The addLike() function is supposed to keep track of which endorsement cards have been liked using an array stored in localStorage rather than the firebase database so that it accurately tracks whether a specific user has liked a card rather than whether the card has been liked by anyone at all. Local storage is (theoretically) being updated each time the localLikeArray is updated using useEffect(), but the problem I'm having is that it seems like useEffect() somehow resets localLikeArray each time it runs. As a subset of this problem, resetLikes() also doesn't work. Can anyone help me understand what's going on?

https://github.com/cwatersaudio/Scrimba-Solo-Projects/tree/main/Endorsements

https://gleaming-licorice-029ec9.netlify.app/

GitHub

Contribute to cwatersaudio/Scrimba-Solo-Projects development by creating an account on GitHub.

formal vapor
#

@cedar star Thanks for looking at it! Do you see the issue I described regarding the localLikes array at localStorage?

cedar star
#

but we can jump in a voice channel and you can show me if you want

#

i'm free for the next 10 min

#

your issue seems easy to fix once we've got all the info

formal vapor
cedar star
#

I should be free in an hour. What about you?

#

@formal vapor

formal vapor
cedar star
#

Will you be there around that time?

formal vapor