facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
229.3k stars 46.96k forks source link

Bug: Nothing returned from renderer when returning undefined #20089

Closed raRaRa closed 4 years ago

raRaRa commented 4 years ago

React version: 17.0.0

Steps To Reproduce

  1. return undefined from a React component

Link to code example: https://codesandbox.io/s/blazing-rain-jtdzy?file=/src/App.js

The current behavior

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

The expected behavior

Nothing should be rendered like in earlier React versions.

raRaRa commented 4 years ago

The simple fix is of course to return null instead of return undefined, but I never saw this breaking change documented for React 17.0.0. Apologies if this is by design.

kachkaev commented 4 years ago

This is intentional. See https://github.com/facebook/react/issues/19548, which was closed by https://github.com/facebook/react/pull/19550

Here is a blog post section on this behaviour: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#consistent-errors-for-returning-undefined

Your codesandbox example would produce a warning in React 16 too.

raRaRa commented 4 years ago

@kachkaev Thanks. I've never noticed this warning during the development of my app in React 16, very odd. I'll close this issue since this is by design.

Thanks again.