Skip to content
Advertisement

Getting undefined props in functional react components

How to pass the {requests} prop to the RequestRow component after executing the setRequests? My understanding is that the requests get initialized as undefined in the beginning and before being set with the asynchronously called object, it gets passed to the RequestRow component as undefined, and the error occurs.

JavaScript

The RequestRow component is shown below. It takes in the {requests} props, which unfortunately is undefined.

JavaScript

The snapshot of the error is shown below:

enter image description here

Advertisement

Answer

I think React is trying to render your component before your promises resolve. If that’s the case, all you need to do is set a default value (an empty array in your case) for your requests.

JavaScript

May the force be with you.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement