【发布时间】:2019-08-07 17:13:19
【问题描述】:
所以我有一个名为 Header 的组件,它将根据用户是否登录显示导航栏,我传递的道具是来自父组件的道具,它返回 true,因为用户在登录后已经通过身份验证
应用
<Header IsLoggedIn={this.state.IsLoggedIn} />
那么这是我的未呈现的 Header 组件
标题
// stateless functional component
import React from 'react';
import { NavLink } from 'react-router-dom'; //import Navlink to create nav links and to put active class on any link that is active
import UserGreeting from './UserGreeting'
import GuestGreeting from './GuestGreeting'
/*Header- Displays the top menu bar for the application and
includes buttons for signing in and signing up
(if there's not an authenticated user) or the user's first and last name
and a button for signing out (if there's an authenticated user).*/
function Header(props) {
const isLoggedIn = props;
console.log(props)
if (isLoggedIn ===true) {
return <UserGreeting />;
}
else if(isLoggedIn===false) {
return <GuestGreeting />;
}
}
export default Header;
这是我重新加载页面时遇到的错误:
Uncaught Invariant Violation: Header(...): 没有从渲染返回。这通常意味着缺少 return 语句。或者,不渲染任何内容,返回 null。 有人可以帮忙吗?
【问题讨论】:
标签: javascript reactjs react-router react-dom