我有一个简单的 LoginForm,我尝试从 redux 映射状态以进行react。这是我来自 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);
减速器包含属性 loginObj,如果我打印我看到的商店:
loginObj:
Object { loginState="false", user="", password=""}
减速器:
const reducers = combineReducers({
loginObj: loginReducer
});
...
但是,当我尝试访问props时,似乎 this.props 是空的。
this.props.loginObj.loginState - this.props 为空
更新:登录表单: