繁体   English   中英

React Component中的渲染没有返回任何内容

[英]Nothing was returned from render in React Component

在App index.js文件中,我将重定向作为基于用户身份验证的navigate处理。

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

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

export default withAuthentication(IndexPage);

重定向的作品,但我在收到错误IndexAuth并导致页面routes.DASHBOARD不渲染。

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

据我了解,我需要返回一些东西供组件render 我怎样才能做到这一点?

如果IndexAuth只是导航的包装器,那么导航需要返回一些东西,而不是返回东西。 如果导航是您的函数,则为其添加返回值。 否则,将其添加到IndexAuth。

只是为了扩展Joseph Sible的答案,为同一条船上的其他人提供解决方案。

我通过在IndexAuth返回null来修复此问题

const IndexAuth = () => {
  navigate(routes.DASHBOARD);
  return null;
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM