如何解决类型错误:无法读取未定义的属性“isAuthenticated”
我正在尝试修复以下错误:
TypeError: 无法读取未定义的属性“isAuthenticated” 导航栏 E:/smnd/client/src/components/layout/Navbar.js:7
import { logout } from '../../actions/auth';
const Navbar = ({ auth: { isAuthenticated,loading },logout }) => {
这是我的导航栏代码,我已经定义了我的 isAuthenticated 我已经在 auth.js reducers 文件中定义了它......中间件工作不正常
import React,{ Fragment } from 'react';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { logout } from '../../actions/auth';
const Navbar = ({ auth: { isAuthenticated,logout }) => {
const authLinks = (
<ul>
<li>
<a onClick={logout} href='#!'>
<i className="fas fa-sign-out-alt"></i>{' '}
<span className="hide-sm">logout</span>
</a></li>
{/* <li>
<Link to='/profiles'>Developers</Link>
</li>
<li>
<Link to='/dashboard'>
<i className='fas fa-user' />{' '}
<span className='hide-sm'>Dashboard</span>
</Link>
</li>
<li>
<a onClick={logout} href='#!'>
<i className='fas fa-sign-out-alt' />{' '}
<span className='hide-sm'>logout</span>
</a>
</li> */}
</ul>
);
const guestLinks = (
<ul>
<li>
<Link to='#!'>Developers</Link>
</li>
<li>
<Link to='/register'>Register</Link>
</li>
<li>
<Link to='/login'>Login</Link>
</li>
</ul>
);
return (
<nav className='navbar bg-dark'>
<h1>
<Link to='/'>
<i className='fas fa-code' /> DevConnector
</Link>
</h1>
{!loading && (
<Fragment>{isAuthenticated ? authLinks : guestLinks}</Fragment>
)}
</nav>
);
};
Navbar.propTypes = {
logout: PropTypes.func.isrequired,auth: PropTypes.object.isrequired
};
const mapStatetoProps = state => ({
auth: state.auth
});
export default connect(
mapStatetoProps,{ logout }
)(Navbar);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。