question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It would be nice if a React.Component could render undefined

See original GitHub issue

just 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:closed
  • Created 8 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

35reactions
grovesNLcommented, Jun 1, 2017

With more codebases moving to TypeScript and Flow, I think returning undefined would be very useful here. I try to avoid using null anymore, except when libraries force its usage.

12reactions
gaearoncommented, Jan 26, 2017

We might allow returning undefined in the future.

What’s the best way to write a render returning this.props.optionalProperty && <…>?

Not sure what you’re asking. Can you show a full example you’re having issues with?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found