It would be nice if a React.Component could render undefined
See original GitHub issuejust an idea
It would be nice if a React.Component could render undefined if some, opted in, property like; isLoading is true.
I find myself doing the following quite a bit:
{this.state.something.isLoading ? <MyComponent/> : undefined}
something like the follow might clean this up a bit
<MyComponent isLoading={this.state.something.isLoading}/>
I’m unaware of how to do this if it’s possible already.
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
React 18 allows components to render 'undefined'
Until React 18, if a component rendered undefined , React would throw an error at runtime. //Shape.jsx import React from 'react'; ...
Read more >Render undefined in react component? - Stack Overflow
If the name property doesn't exist on the props object, props.name will just be undefined . However, if there is e.g. no person...
Read more >Conditional Rendering - React
This can help you conditionally render a part of the component while the rest of the output doesn't change. Consider these two new...
Read more >Watch Out for Undefined State - Dave Ceddia
Quick quiz: When a React component loads data from the server in componentWillMount like this one below, what will it render?
Read more >React Component rendering twice, props 'undefined' at first ...
Yeah it will render when state changes. State airLoadRes is initialized to undefined, then set later.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
With more codebases moving to TypeScript and Flow, I think returning
undefined
would be very useful here. I try to avoid usingnull
anymore, except when libraries force its usage.We might allow returning
undefined
in the future.Not sure what you’re asking. Can you show a full example you’re having issues with?