【发布时间】:2017-11-07 16:06:49
【问题描述】:
我有一个简单的 LoginForm,我尝试从 redux 映射状态以做出反应。这是我的 LoginForm.js 代码:
export class LoginForm extends React.Component {
render() {
console.log("**** FORM print store");
console.log(store.getState());
console.log("**** FORM print props");
console.log(this.props);
if(this.props.loginObj.loginState=='true') { // error here
console.log('yes');
}
return (
<div><div/>);
);
}
}
const mapStateToProps = (state) => ({
loginObj : state.loginObj
});
const mapDispatchToProps = (dispatch) => ({
doLogin,
changeText,
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(LoginForm);
reducer 包含属性 loginObj,如果我打印我看到的商店:
loginObj:
Object { loginState="false", user="", password=""}
减速机:
const reducers = combineReducers({
loginObj: loginReducer
});
...
但是当我尝试访问道具时,this.props 似乎是空的。
this.props.loginObj.loginState - this.props 为空
更新: 登录表单:
【问题讨论】:
-
告诉我们
LoginForm。 -
添加了 loginForm 的更新
-
日志
this.props记录了什么? -
打印:对象 {}
-
这很奇怪。我将不得不看到更多
LoginForm。
标签: javascript reactjs redux