How to fix Component should not return undefined, null or false in React

ReactBEGINNERMEDIUMUpdated Dec 9, 2025· 127 views

This error occurs when a React component returns an invalid value like undefined, typically due to a missing return statement. In React versions before 18, components that returned undefined or false would throw this error, though React 18+ is more lenient with undefined returns.

Quick fix

Fixes Component should not return undefined, null or false

// ❌ Incorrect - missing return
const MyComponent = () => {
  <div>Hello World</div>
};

// ✅ Correct - explicit return
const MyComponent = () => {
  return <div>Hello World</div>;
};
  1. Add explicit return statement to function components
  2. Use implicit return with arrow functions
  3. Fix return statement formatting
  4. Return null explicitly when rendering nothing
react — error
// ❌ Incorrect - missing return
const MyComponent = () => {
<div>Hello World</div>
};
// ✅ Correct - explicit return
const MyComponent = () => {
return <div>Hello World</div>;
};
Component should not return undefined, null or false

What this error means

This error appears when a React component fails to return valid JSX or null. It most commonly happens when developers forget to add a return statement in their component function, or when they use incorrect syntax with arrow functions. In JavaScript, when a function doesn't explicitly return a value, it returns undefined by default. React interprets this as an error because it expects components to either return JSX elements or explicitly return null when they should render nothing. The error message "Nothing was returned from render" is React's way of catching this common mistake before it causes rendering issues. While React 18 relaxed this restriction to allow undefined returns (treating them the same as null), earlier versions would throw this error. Even in React 18+, returning undefined is considered poor practice because it's ambiguous whether you intended to return nothing or simply forgot the return statement. Using null is clearer and more intentional.

Typical symptoms

  • Error message "Nothing was returned from render" in the console
  • Component fails to render on the page
  • React DevTools shows the component as mounted but displays nothing
  • TypeScript errors about incompatible return types if using React.FC
  • Application crashes or displays error boundary in development mode

Common causes

  1. Missing return statement in a component function using curly braces
  2. Arrow function with curly braces but no explicit return keyword
  3. Return statement followed by opening parenthesis on the next line (automatic semicolon insertion)
  4. Conditional logic that doesn't return anything in some branches
  5. Accidentally returning false instead of null when component should render nothing
  6. Using array methods like .map() or .filter() without returning the result

How to fix "Component should not return undefined, null or false"

1Add explicit return statement to function components

If your component uses curly braces, ensure you have an explicit return statement:

jsx
// ❌ Incorrect - missing return
const MyComponent = () => {
  <div>Hello World</div>
};

// ✅ Correct - explicit return
const MyComponent = () => {
  return <div>Hello World</div>;
};

This is the most common cause of the error. When using curly braces with arrow functions, JavaScript requires an explicit return statement.

2Use implicit return with arrow functions

Replace curly braces with parentheses for implicit returns:

jsx
// ❌ Incorrect - curly braces without return
const MyComponent = () => {
  <div>Hello World</div>
};

// ✅ Correct - implicit return with parentheses
const MyComponent = () => (
  <div>Hello World</div>
);

// ✅ Also correct - single line implicit return
const MyComponent = () => <div>Hello World</div>;

Implicit returns work when you don't need to declare variables or execute logic before returning JSX.

3Fix return statement formatting

Ensure the opening parenthesis is on the same line as the return keyword:

jsx
// ❌ Incorrect - automatic semicolon insertion
function MyComponent() {
  return
    <div>Hello World</div>
}

// ✅ Correct - opening parenthesis on same line
function MyComponent() {
  return (
    <div>Hello World</div>
  );
}

JavaScript's automatic semicolon insertion treats the first example as return; followed by unreachable code, causing the component to return undefined.

4Return null explicitly when rendering nothing

When a component should conditionally render nothing, return null instead of undefined or false:

jsx
// ❌ Incorrect - returning false
const MyComponent = ({ show }) => {
  if (!show) return false;
  return <div>Content</div>;
};

// ❌ Incorrect - implicit undefined
const MyComponent = ({ show }) => {
  if (!show) return;
  return <div>Content</div>;
};

// ✅ Correct - explicit null
const MyComponent = ({ show }) => {
  if (!show) return null;
  return <div>Content</div>;
};

Returning null is the idiomatic way to tell React "render nothing" and makes your intent clear.

5Ensure all conditional branches return values

Check that every code path in your component returns valid JSX or null:

jsx
// ❌ Incorrect - missing return in else branch
const MyComponent = ({ type }) => {
  if (type === 'A') {
    return <div>Type A</div>;
  } else {
    <div>Other Type</div>; // Missing return!
  }
};

// ✅ Correct - all branches return
const MyComponent = ({ type }) => {
  if (type === 'A') {
    return <div>Type A</div>;
  } else {
    return <div>Other Type</div>;
  }
};

// ✅ Even better - single return point
const MyComponent = ({ type }) => {
  const content = type === 'A' ? 'Type A' : 'Other Type';
  return <div>{content}</div>;
};

Use your IDE's flow analysis or TypeScript to catch paths that don't return values.

6Fix array method returns in JSX

When using .map() or other array methods in JSX, ensure they return elements:

jsx
// ❌ Incorrect - missing return in map
const MyComponent = ({ items }) => {
  return (
    <ul>
      {items.map(item => {
        <li key={item.id}>{item.name}</li> // Missing return!
      })}
    </ul>
  );
};

// ✅ Correct - explicit return
const MyComponent = ({ items }) => {
  return (
    <ul>
      {items.map(item => {
        return <li key={item.id}>{item.name}</li>;
      })}
    </ul>
  );
};

// ✅ Best - implicit return
const MyComponent = ({ items }) => {
  return (
    <ul>
      {items.map(item => (
        <li key={item.id}>{item.name}</li>
      ))}
    </ul>
  );
};

Using parentheses with arrow functions in .map() enables implicit returns and prevents this error.

Advanced notes

React 18 Behavior Change

React 18 relaxed the restriction on undefined returns. Components that return undefined will render nothing instead of throwing an error, matching the behavior of returning null. However, this change was primarily made to support async components and Suspense, not to encourage returning undefined from regular components.

Why Return null Instead of undefined

Even though React 18+ allows undefined, returning null is still recommended for clarity:
- It explicitly communicates intent to render nothing
- It's distinguishable from accidentally forgetting a return statement
- Linters can provide better error messages when you forget to return
- It's compatible with all React versions, not just 18+

TypeScript Considerations

When using TypeScript with React, the React.FC type enforces stricter return types:

typescript
// TypeScript error with React.FC and undefined return
const MyComponent: React.FC = () => {
  // This may cause TypeScript errors depending on @types/react version
  return undefined;
};

// Always safe with null
const MyComponent: React.FC = () => {
  return null;
};

The TypeScript definitions for React components have evolved, and older versions of @types/react don't allow undefined returns even in React 18+.

Linting Rules

ESLint with the React plugin can catch missing returns:

json
{
  "rules": {
    "react/require-render-return": "error",
    "consistent-return": "error"
  }
}

These rules help catch the error at development time before it reaches production.

Class Components

In class components, the render() method must return JSX or null. Forgetting to return from render() causes the same error:

jsx
class MyComponent extends React.Component {
  render() {
    // ❌ Missing return
    <div>Hello</div>
  }
}

class MyComponent extends React.Component {
  render() {
    // ✅ Correct
    return <div>Hello</div>;
  }
}

Modern React development favors function components, but the same principles apply to class component render methods.

Frequently asked questions

What does "Component should not return undefined, null or false" mean?
This error appears when a React component fails to return valid JSX or null. It most commonly happens when developers forget to add a return statement in their component function, or when they use incorrect syntax with arrow functions. In JavaScript, when a function doesn't explicitly return a value, it returns undefined by default.
How do I fix "Component should not return undefined, null or false"?
This error occurs when a React component returns an invalid value like undefined, typically due to a missing return statement. In React versions before 18, components that returned undefined or false would throw this error, though React 18+ is more lenient with undefined returns.
What causes "Component should not return undefined, null or false"?
Missing return statement in a component function using curly braces Arrow function with curly braces but no explicit return keyword Return statement followed by opening parenthesis on the next line (automatic semicolon insertion)
Is the "Component should not return undefined, null or false" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading