简体   繁体   English

即使操作成功执行后,React-Native中的Redux状态为null

[英]Redux state null in React-Native even after execution of the action being successful

Redux state is null, even after execution of the action being successful! 即使成功执行操作,Redux状态也为空!

My app has a login button which when clicked, it triggers an action: 我的应用程序有一个登录按钮,单击该按钮会触发一个操作:

src / Screen / Member / SignIn / index.js, line 40: this.props.tryLogin (email, password) src / Screen / Member / SignIn / index.js,第40行:this.props.tryLogin(电子邮件,密码)

In the action file: 在操作文件中:

/src/actions/userActions.js /src/actions/userActions.js

The action tryLogin () is executed successfully, and there is the normal dispatch: tryLogin ()已成功执行,并且有正常的分派:

const action = userLoginSuccess (res);
dispatch (action);

The execution succeeds, and the app redirects to app home: 执行成功,并且应用重定向到应用主目录:

/src/Screen/Public/Home/index.js /src/Screen/Public/Home/index.js

The problem is right here, when I try to read the redux state: in the file: 当我尝试读取文件中的redux状态时,问题就在这里:

/src/Component/Menu/Left/index.js, line: 206 /src/Component/Menu/Left/index.js,第206行

mapStateToProps () , mapStateToProps ()

The state is null , even with the action userLoginSuccess () having been successfully executed !!! 即使成功执行了userLoginSuccess ()操作,状态也为null !!!

My repository to test: https://github.com/tmacedo2014/EstudoReactNative 我要测试的存储库: https : //github.com/tmacedo2014/EstudoReactNative

Data to use in test login: email: tiberius.macedo@gmail.com pass: 123456 测试登录中使用的数据:电子邮件:tiberius.macedo@gmail.com通过:123456

You have a typo in your action type. 您的动作类型有错字。 In actions/userActions.js you named the action constant USER_LOGIN_SUCESS but in reducers/userReducer.js you import USER_LOGIN_SUCCESS . actions / userActions.js中,您将动作常量命名为USER_LOGIN_SUCESS而在reducers / userReducer.js中,您则导入了USER_LOGIN_SUCCESS

If you fix this typo, everything else looked like it was hooked up correctly. 如果您解决了该错字问题,其他所有内容似乎都已正确连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM