What's the reason that a stateless function cannot return null?
See original GitHub issueWhen 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:
- Created 8 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top 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 >
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
Fixed in https://github.com/facebook/react/pull/5884
@hnordt
<noscript />
is what React currently uses when you returnnull
.