× TypeError: Cannot destructure property 'shippingInfo' of 'order' as it is undefined

TypeError: Cannot destructure property ‘shippingInfo’ of ‘order’ as it is undefined.

I’m Nasir Shoyas
I’m getting ( TypeError: Cannot destructure property ‘shippingInfo’ of ‘order’ as it is undefined.) can anyone help me with this?

Here is my code and output:
All information from Database:

My code:

Error from Browser:

Error from Browser’s console:

If you look at the console log right before the error, you will see that order is an empty object. That is why order.shippingInfo is undefined.

I want the output will be destructed value. How can I find that?

Well, if it’s undefined there’s nothing to destructure, so you need to only try to do that if you know there’s an object there. You can’t try to access object properties before that object exists.

Your selector on line 14 aknowledges that state.orderDetails may not exist, and provides an empty object as a default. In order to stop getting the type error, the rest of your code needs to follow that same principle of handling the case where order is an empty object.

Thanks a lot for giving you effort, ArielLeslie and DanCouper
Line 14: state.orderDetails is not exist. That’s why it returns undefined. But, I’ve done same method of code for other component then it worked. Why line 14 does not exist? I cann’t understand…
Here I’m sharing my full code of this component. So that you can find the actual mistake of mine.

Order Details Constant:

Order Details Reducer:

Order Details Store:

Order Details Action:

Order Details UI Component: [NB.: Here state.orderDetails at 15 no of line and || {} not uses. If i though use || {} then i also get same return]

At least I can solve this issue by myself.
I’m describing about this error:

OrderDetail part -1 : Line 15
order needs an empty string. without empty string order gets just prototype.
just watch the pic u can understand clearly:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.