bradtraversy / proshop_mern

Shopping cart built with MERN & Redux
1.99k stars 1.18k forks source link

After creating the cart reducer and action, when i pass the state of the cart it returns this error #100

Closed nkayilovette03 closed 3 years ago

nkayilovette03 commented 3 years ago

Unhandled Rejection (TypeError): can't access property "cartItems", getState().cart is undefined

This screen is visible only in development. It will not appear if the app crashes in production. Open your browser’s developer console to further inspect this error. Click the 'X' or hit ESC to dismiss this message.

basir commented 3 years ago

hello there make sure you have set a default value for cart in Store.js like this: https://github.com/bradtraversy/proshop_mern/blob/master/frontend/src/store.js#L69 also in the cartReducer you have a default value in the function parameter like this: https://github.com/bradtraversy/proshop_mern/blob/master/frontend/src/reducers/cartReducers.js#L10

you can clone this repo and run it on your computer. It works.

https://github.com/bradtraversy/proshop_mern/

Then compare your code with this.