Yes you can, but instead of blank, simply return null if you don't want to render anything from component, like this:

return (null);

Another important point is, inside JSX if you are rendering element conditionally, then in case of condition=false, you can return any of these values false, null, undefined, true. As per DOC:

booleans (true/false), null, and undefined are valid children, they will be Ignored means they simply don’t render.

All these JSX expressions will render to the same thing:

<div />

<div></div>

<div>{false}</div>

<div>{null}</div>

<div>{undefined}</div>

<div>{true}</div>

Example:

Only odd values will get rendered, because for even values we are returning null.

const App = ({ number }) => {
  if(number%2) {
    return (
      <div>
        Number: {number}
      </div>
    )
  }
  
  return (null);           //===> notice here, returning null for even values
}

const data = [1,2,3,4,5,6];

ReactDOM.render(
  <div>
    {data.map(el => <App key={el} number={el} />)}
  </div>,
  document.getElementById('app')
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id='app' />

Answer from Mayank Shukla on Stack Overflow
Top answer
1 of 9
443

Yes you can, but instead of blank, simply return null if you don't want to render anything from component, like this:

return (null);

Another important point is, inside JSX if you are rendering element conditionally, then in case of condition=false, you can return any of these values false, null, undefined, true. As per DOC:

booleans (true/false), null, and undefined are valid children, they will be Ignored means they simply don’t render.

All these JSX expressions will render to the same thing:

<div />

<div></div>

<div>{false}</div>

<div>{null}</div>

<div>{undefined}</div>

<div>{true}</div>

Example:

Only odd values will get rendered, because for even values we are returning null.

const App = ({ number }) => {
  if(number%2) {
    return (
      <div>
        Number: {number}
      </div>
    )
  }
  
  return (null);           //===> notice here, returning null for even values
}

const data = [1,2,3,4,5,6];

ReactDOM.render(
  <div>
    {data.map(el => <App key={el} number={el} />)}
  </div>,
  document.getElementById('app')
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id='app' />

2 of 9
60

Some answers are slightly incorrect and point to the wrong part of the docs:

If you want a component to render nothing, just return null, as per doc:

In rare cases you might want a component to hide itself even though it was rendered by another component. To do this return null instead of its render output.

If you try to return undefined for example, you'll get the following error:

Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

As pointed out by other answers, null, true, false and undefined are valid children which is useful for conditional rendering inside your jsx, but it you want your component to hide / render nothing, just return null.

EDIT React 18:

React 18 will allow rendering undefined instead of throwing. See this announcement.

Discussions

reactjs - Return null from a stateless component/"functional component" - Stack Overflow
I have a stateless functional component in React 0.14 that worked in React 0.13, but now returns the following error: No render method found on the returned component instance: you may have for... More on stackoverflow.com
🌐 stackoverflow.com
May 19, 2016
reactjs - What is the best case for defining function without any dependencies in React functional component? - Stack Overflow
I'm always confused when define function in React functional component without any dependencies. ... const HelloWorld = () => { const getHelloWorldText = useCallback(() => { return "HelloWorld" }, []) return <>{getHelloWorldText()} } More on stackoverflow.com
🌐 stackoverflow.com
Same file components vs functions that return JSX
Please do the second thing and write dedicated components. I have no problem with multiple components in a single file. I view functions that return JSX as an antipattern. React components are literally there for this purpose. The take arguments (props) and return JSX. More on reddit.com
🌐 r/reactjs
19
24
July 25, 2022
Is it possible to use React without rendering HTML?
The component I'm thinking of is something that you pass some data to, and it'll send data back to a javascript function outside of react. I know that can be done, and I've done that part myself, but I'm not sure how you would do this without rendering html as it is required. Is this even a practical use case for react? ... React is a library for building views. What features of React lead you to want to use it for your task? ... render() { return ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
React
react.dev › learn › keeping-components-pure
Keeping Components Pure – React
React’s rendering process must always be pure. Components should only return their JSX, and not change any objects or variables that existed before rendering—that would make them impure! ... let guest = 0; function Cup() { // Bad: changing a preexisting variable!
🌐
Moox
moox.io › blog › how-i-write-stateless-react-components
How I write React stateless functional components
May 23, 2018 - Because when you want to add computations, breakpoints, logs etc, you can’t do that easily without return statement. You can’t inject a computation (except inline maybe - but I am not a one liner guy anymore). It can become annoying to have to edit the component wrapper to add the return statement.
🌐
DEV Community
dev.to › igor_bykov › react-calling-functional-components-as-functions-1d3l
React: Calling functional components as functions - DEV Community
August 27, 2020 - It's very similar to assigning ... a non-component is dangerous. Using functions that return JSX without being a component might be officially considered to be an anti-pattern in the future....
🌐
Robin Wieruch
robinwieruch.de › react-function-component
React Function Components - Robin Wieruch
December 23, 2024 - Both React Arrow Function Components use a function block body now. However, the second component can optionally be made more lightweight with a concise body for the function, because it only returns the output of the component without doing something else in between.
Find elsewhere
🌐
DEV Community
dev.to › ucvdesh › stop-returning-null-components-312k
Stop returning NULL components - DEV Community
May 27, 2021 - ... To avoid these problems the correct way to do is to do the conditionals on the parent component to avoid even call that child component. We're gonna be using the same example: import React, {useState} from 'react'; export const MyComponent ...
🌐
Medium
medium.com › @davidkelley87 › stop-using-return-null-in-react-a2ebf08fc9cd
Stop using “return null” in React | by David | Medium
March 1, 2023 - When a component returns false, ... tells React not to render any of the component's children. This ensures that the component and its children remain connected to the tree, avoiding the issues that can arise from using return null.
🌐
LogRocket
blog.logrocket.com › home › pure components in react: using purecomponent and react.memo
Pure components in React: Using PureComponent and React.memo - LogRocket Blog
March 4, 2025 - React stateless function components are functions that do not manage any state. They are a simple way to define components that don’t need to manage state or lifecycle methods. In essence, stateless function components are JavaScript functions ...
🌐
Reddit
reddit.com › r/reactjs › same file components vs functions that return jsx
r/reactjs on Reddit: Same file components vs functions that return JSX
July 25, 2022 -

Hey ya'll, question about the performance/best practice when comparing using a same file component that, let's say will never be re-used, vs adding a function inside the main component that simply returns some JSX.

These examples are totally simplified here, and assume each example is a single file.Let's say this:

export const App = () => {

&nbsp;const [title, setTitle] = useCustomHook('My Title');

const renderTitle = () => {

return <h1>{title}</h1>;

};

return (

<>

{renderTitle()}

<p>Some other text...</p>

</>

);

};

vs this:

const MyTitle = (title) => {

return <h1>{title}</h1>;

};

export const App = () => {

const [title, setTitle] = useCustomHook('My Title');

return (

<>

<MyTitle title={title} />

<p>Some other text...</p>

</>

);

};

I have always leaned towards the first option as long as I know that the JSX that's returned from the renderTitle function is only relevant to App.

Thoughts?

Top answer
1 of 4
92

As of React >= 16.2 it is possible to use any of these versions:

render() { 
   return false; 
}

render() { 
   return null; 
}

render() { 
   return []; 
}

render() { 
   return <React.Fragment></React.Fragment>; 
}

render() { 
   return <></>; 
}

Returning undefined does not work.


The component I'm thinking of is something that you pass some data to, and it'll send data back to a javascript function outside of react.

Why would you want to create a component for that? Most of the time a regular js function in an existing component can be enough.

One usecase is for exemple to setup a side-effect when component is mounted and tear it down when it unmounts. For exemple if you have a ReactNative mobile app with portrait orientation, you could imagine a <Landscape/> component, that, when mounted, would allow temporarily to display the app in landscape orientation, and when unmounted, orientation would be reset to app default. You can surely manage this orientation change on an existing component, but creating a dedicated component might be more handy and reusable.

Note that React can also run on the server side so I guess it is possible to use it in such a way that it doesn't involve any DOM modifications (but maybe only the virtual DOM computation).

2 of 4
22

Just to clarify benno's comments. The ReactComponent.render method doc states:

You can also return null or false to indicate that you don't want anything rendered. Behind the scenes, React renders a <noscript> tag to work with our current diffing algorithm. When returning null or false, this.getDOMNode() will return null.

🌐
InfoWorld
infoworld.com › home › software development › programming languages › javascript
How to use React functional components | InfoWorld
January 14, 2021 - The core purpose of a React component is to define the displayed view and bind it to the code that drives its behavior. React’s functional components distill this down to the simplest possible profile: a function that receives properties and returns a JSX definition.
🌐
Medium
medium.com › @housecor › react-stateless-functional-components-nine-wins-you-might-have-overlooked-997b0d933dbc
React Stateless Functional Components: Nine Wins You Might Have Overlooked | by Cory House | Medium
July 29, 2019 - The 27 line component became 21 lines, a ~20% reduction. You can go a step further on simple components. With a single line return statement, you can omit the return and curly braces.
🌐
React
legacy.reactjs.org › docs › components-and-props.html
Components and Props – React
All React components must act like pure functions with respect to their props. Of course, application UIs are dynamic and change over time. In the next section, we will introduce a new concept of “state”. State allows React components to change their output over time in response to user actions, network responses, and anything else, without violating this rule.
🌐
Stack Overflow
stackoverflow.com › questions › 70637969 › how-functional-components-are-working-without-essential-render-function
reactjs - How Functional components are working without essential render function? - Stack Overflow
January 9, 2022 - In react functional components there is the useEffect Hook and in your case the: ... Sign up to request clarification or add additional context in comments. ... Yes, you are correct. In functional components, there is no need for a render function. ...
🌐
Reddit
reddit.com › r/react › am i supposed to never create functions inside react functional components?
r/react on Reddit: Am I supposed to never create functions inside React functional components?
December 7, 2022 -

https://beta.reactjs.org/learn/adding-interactivity#state-a-components-memory

export default function Gallery() {
  const [index, setIndex] = useState(0);
  const [showMore, setShowMore] = useState(false);

  function handleNextClick() {
    setIndex(index + 1);
  }

  function handleMoreClick() {
    setShowMore(!showMore);
  }
....

So on every render we are creating new functions handleNextClick, handleMoreClick

Should we pull these out of Gallery and pass the "set" state functions as parameters?

I only ask this because I read somewhere best practice is to NOT have functions inside your React functional components <-- trying to confirm if this is true? Small functions allowed? Doesn't matter?

🌐
React
react.dev › reference › react › Component
Component – React
You should write the render method as a pure function, meaning that it should return the same result if props, state, and context are the same. It also shouldn’t contain side effects (like setting up subscriptions) or interact with the browser APIs. Side effects should happen either in event handlers or methods like componentDidMount.