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.

What's the reason that a stateless function cannot return null?

See original GitHub issue

When I return null from a stateless function I receive an error message. I would like to know what’s the reason that a stateless function cannot return null.

Here is my sample code:

const MeetingMembers = ({ members, isLoading, error }) => {
  if (isLoading) {
    return <i className="fa fa-spinner fa-spin" />;
  }
  if (error) {
    return <div className="alert alert-danger">{error}</div>;
  }
  if (!members) {
    return null; // if no members was passed the component should'nt be displayed yet
  }
  return <pre>{JSON.stringify(members, null, 2)}</pre>;
};

Thank you.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jimfbcommented, Jan 29, 2016
2reactions
syranidecommented, Nov 2, 2015

@hnordt <noscript /> is what React currently uses when you return null.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React stateless functional component should return null but ...
Invariant Violation: FormErrors(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, ...
Read more >
Is it better to return NULL or empty values from functions ...
An empty object implies data has been returned, whereas returning null clearly indicates that nothing has been returned. Additionally, returning ...
Read more >
React Stateless Functional Components: Nine Wins You Might ...
With React's stateless functional components, each component can be easily tested in isolation. No mocking, state manipulation, special libraries, or tricky ...
Read more >
Can a function return null? - Page 2 — oracle-tech
What I do know is that 'null' is a 'state'. Datatypes are in the 'metadata' domain. Oracle functions return instances of datatypes.
Read more >
Best Practice: Should functions return null or an empty object?
For example if you are calling a method that requests a list of files in a specific folder, returning null indicates that the...
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