Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nothing was returned from render in React Component

In the App index.js file I am handling redirects as navigate based on user authentication.

const IndexAuth = () => navigate(routes.DASHBOARD);

const IndexPageContent = withAuthorization(authCondition)(() => (
 <AuthUserContext.Consumer>
    {authUser => (authUser ? <IndexAuth /> : null)}
  </AuthUserContext.Consumer>
));

export default withAuthentication(IndexPage);

The redirect works but I am getting an error at IndexAuth and causing the page at routes.DASHBOARD to not render.

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

As I understand it, I need to return something for the component to render. How can I do this?

like image 627
Darren Avatar asked Jun 03 '26 15:06

Darren


1 Answers

If IndexAuth is just a wrapper around navigate, then navigate needs to return something, which it doesn't. If navigate is your function, then add a return value to it. Otherwise, add it to IndexAuth.

like image 89
Joseph Sible-Reinstate Monica Avatar answered Jun 05 '26 03:06

Joseph Sible-Reinstate Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!