Skip to content

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

@hnordt

Description

@hnordt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions