CoreyWarren / coldcmerch.com

Creating a Django/React/JWT/Redux E-Commerce store for my good friends in Cold Cut. Shout out to Elmar, Lou, and Brian.
1 stars 0 forks source link

Checkout Page -- CLEAR CART WHEN PAYMENT GOES THRU~! (Stripe Webhooks) #93

Closed CoreyWarren closed 1 year ago

CoreyWarren commented 1 year ago

Finished, but with bugs.

After deployment, when the dev server is running, look into re-loading Cart Page, ONLY after a successful order is made, but not EVERY time cart page is loaded. Why? Because doing a full refresh messes with the DOM efficiency and state management. Here, break it down, ChatGPT(4):


Adding a refresh button is considered a hacky solution primarily because it doesn't address the root cause of the problem. It's essentially a band-aid fix, and can often lead to more complex issues down the line. Here are a few reasons why this is not an ideal solution:

State Management: In modern web development, especially when using libraries like React, state management is crucial. The state of your application should determine what is rendered on the screen. By forcing a page refresh, you're essentially resetting your entire application's state, which is typically not what you want.

User Experience: Reloading the page can often lead to a poor user experience. It can cause flickers on the screen, and potentially disrupt the user's interaction with the application. In the worst case, users might lose unsaved data.

Performance: Reloading the entire page can be expensive in terms of performance. It means re-downloading resources, re-parsing JavaScript, re-rendering the DOM, and so on. It's much more efficient to only update the parts of the page that actually need to change.

Avoiding the Root Cause: By adding a refresh button, you're not addressing the underlying issue. It's better to understand why your state isn't updating as expected and to fix that issue directly. This might involve debugging your state management logic, or it could mean improving your error handling so that the application can recover from errors without needing a full page refresh.

In conclusion, while a refresh button might seem like a quick fix, it's often better to invest time in proper error handling and state management. It might take more time upfront, but it will lead to a more stable, maintainable, and user-friendly application in the long run.