thapatechnical / thapareactecom

535 stars 516 forks source link

Fix uncaught type error #46

Closed rohitverma0234 closed 7 months ago

rohitverma0234 commented 7 months ago

Fixed Bug in [cartReducer.js, Cart.js, filterReducer.js, Footer.js, CartItem.js, Product.js]

Summary: This pull request addresses the Uncaught TypeError in all the components . This pull request addresses the issue where the website was failing to load for users. The bug prevented users from accessing the website and resulting in a poor user experience.

Changes Made:

By adding the state.cart !== null condition before attempting to use the reduce function, ensure that the reduce operation is only performed when state.cart is not null, thus avoiding the TypeError. By adding the state.cart !== null check before attempting to use the find method, you ensure that the find operation is only performed when state.cart is not null, thus avoiding the TypeError. In Cart.js, the cart && cart.length === 0 check ensures that the cart variable is not null or undefined before attempting to access its length property. If cart is null or undefined, the conditional check will short-circuit and prevent the error. If cart is an empty array, the condition will evaluate to true, and the JSX for indicating an empty cart will be rendered appropriately. the cart && cart.map(...) expression checks if cart is not null or undefined before attempting to call the map method on it.