Open Nishidhachaudhari opened 1 year ago
In my Case it was causing because of cart context Change your code in cart context
const getLocalCartData = () => {
let localCartData = localStorage.getItem("thapaCart");
const parsedData = JSON.parse(localCartData);
if (!Array.isArray(parsedData)) return [];
return parsedData;
};
that should work
let getLocalCartData = JSON.parse(localStorage.getItem('userCartData')) ? JSON.parse(localStorage.getItem('userCartData')) : []; replace it with this code,
cart Reducer.js:138 Uncaught TypeError: Cannot read properties of null (reading 'reduce')
let getLocalCartData = JSON.parse(localStorage.getItem('userCartData')) ? JSON.parse(localStorage.getItem('userCartData')) : [];
The easiest way is to change the 2nd line (if condition) in the following code in cart_context.js:
let localCartData = localStorage.getItem("thapaCart");
if (localCartData === []) {
return [];
} else {
return JSON.parse(localCartData);
}
};
To:
if (localCartData.length === 0)
cart Reducer.js:138 Uncaught TypeError: Cannot read properties of null (reading 'reduce')