react-native - React redux 数据未成功通过
问题描述
我正在尝试将反应数据传递给 redux,但它似乎并没有成功通过,即使我编写的代码与教程完全一样。
以下是相关功能:
在 components/login-form.js
testFunction(text) {
console.log("The text entered is: ", text); //this reflects successful text entry
this.props.authInputChange({'field': 'email', 'value:': text});
}
const mapStateToProps = state => {
console.log("The state is: ", state); //this does not get updated
return {
email: state.auth.email,
password: state.auth.password
}
};
export default connect(mapStateToProps, { authInputChange, login })(LoginForm);
在行动/index.js
export const authInputChange = ({ field, value }) => {
console.log("The value entered is: ", value); //this value is empty
return {
type: 'AUTH_INPUT_CHANGE',
payload: { field, value }
};
}
现在,即使我完全按照教程进行了操作(除了我自己添加的 console.log 语句),我怀疑讲师犯了一个错误,这就是为什么有些事情没有通过它应该在的地方。但我不知道它会是什么,因为我是 redux 的菜鸟。
谢谢您的帮助!
解决方案
回顾这一行:
authInputChange({'field': 'email', 'value:': text})
您设置value:
为text
not value
。所以你要:
authInputChange({'field': 'email', 'value': text})
另外,我假设您的减速器设置正确。
旁注:这也是我不想在对象键周围加上引号的原因。如果你没有在周围加上引号,value:
你会立即看到这个错误。
推荐阅读
- c++ - Bjam 如何打印编译中使用的包含路径
- django - AttributeError:模块“student.models”没有属性“ManyToManyField”
- reactjs - 与 getServerSideProps 一起使用时,带有 SWR 的 NextJS 在验证期间显示 initialData
- apache - 将 mod_rewrite 与变量一起使用(用于在 htaccess 中进行代理)?
- github - 有谁知道如何自动化 TruffleHog 扫描?
- java - 为什么我的线程在调用服务方法时阻塞
- react-native - undefined is not an object(evalating 'this.localStorage.getItem') react-native中的错误
- typescript - 尝试发送消息时出现错误“Office.context.ui.messageParent 不是函数”
- spring - Spring Integration 重试建议配置
- c# - 从 GitHub(PowerShell 或 .net)上的私有仓库下载资产