Skip to content

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

Open
henriqpohl wants to merge 1 commit into
felipemotarocha:mainfrom
henriqpohl:main
Open

fix: ensure persistence don’t be empty after refresh page and remove products from LocalStorage when user remove any product from cart#29
henriqpohl wants to merge 1 commit into
felipemotarocha:mainfrom
henriqpohl:main

Conversation

@henriqpohl
Copy link
Copy Markdown

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
@vercel
Copy link
Copy Markdown

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