Home » Javascript » Is it better to pass null or undefined to a component while data is being fetched?

Is it better to pass null or undefined to a component while data is being fetched?

Posted by: admin August 19, 2018 Leave a comment

Questions:

In my react app, I’m often fetching data from an API, which leaves some time where my components are not able to render data. From my research, I now understand that if you pass undefined, defaultProps will be used, but if you pass null, defaultProps is ignored.

The way my code is currently structured, I have defaultProps in a component, but its parent passes null while data is loading, so I’m null checking everything anyway.

Does it make more sense to manually be passing around undefined values to trigger defaultProps (in the context of fetching data)?

Also, does this also apply to my redux selectors (mapStateToProps)?

e.g.

<Component bedrooms={bedrooms || undefined} />
Answers: