[英]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.