如何解决如何使用React Local Compoent道具和Redux道具
我希望能够使用来自redux的本地道具和值。尝试使用此方法 this.props.manageUsers 时,始终未定义。我想使用本地组件状态道具以及Redux的值。当redux正在处理显示用户信息的操作时,本地道具将跟踪组件的特定状态,例如单击按钮等。我是Redux的新手,但从文档看来这是可能的,而且我可能还不太熟悉。任何有关如何正确执行此操作的指示将不胜感激。
mport React,{ Component } from 'react';
import style from './Admin.module.css'
import { connect } from 'react-redux';
class Admin extends Component {
state = {
manageUsers: false
}
render() {
console.log(this.props);
return (
<div className={style.container}>
{/* shows undefinded */}
{ String( this.props.manageUsers) + '\n'}
{/* shows "true" */}
{String(this.props.isAuthd)}
</div>
)
}
}
const mapStateToProps = (state,ownProps) =>{
return {
isAuthd: state.user.isAuthd,}
}
export default connect(mapStateToProps)(Admin);
class Admin extends Component {
state = {
manageUsers: false
}
render() {
console.log(this.props);
return (
<div className={style.container}>
{/* CODE */}
{ String( this.props.manageUsers) + '\n'}
{String(this.props.isAuthd)}
</div>
)
}
}
const mapStateToProps = (state,}
}
export default connect(mapStateToProps)(Admin);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。