Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure persistence don’t be empty after refresh page and remove products from LocalStorage when user remove any product from cart #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henriqpohl
Copy link

Description:
After we did the persistent cart we got an error on the build process. It was previous fixed but after this the build process was successful but the persistent cart stopped working.
Every time after the user refreshes the page all objects inside the LocalStorage become empty.

Context:
These changes will ensure that the persistence cart will work on build process and on production and product will be deleted from LocalStorage when user removes it from cart.

Changes:
1: Create a LOCAL_STORAGE_KEY to make it easy to change or maintain in the future.
2: Pass the LocalStorage as String to ensure that it is the behavior.
3: Verify typeof window !== "undefined" if so, ".getItem()" to or ".setItem()" from LocalStorage.
4: Verify if "products.length" equal 0 if so, thats mean user removed some products from the cart and need to remove it from LocalStorage also.

Cheers! 🍺

…products from LocalStorage when user remove any product from cart
Copy link

vercel bot commented Feb 27, 2024

Someone is attempting to deploy a commit to a Personal Account owned by @felipemotarocha on Vercel.

@felipemotarocha first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant