反应 redux 数据未成功传递



我正在尝试将反应数据传递给 redux,但它似乎没有成功通过,即使我编写的代码与教程完全相同。

以下是相关功能:

在组件/登录表单中.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);

在操作/索引中.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 }
};
}

现在,即使我完全遵循了教程(控制台.log语句除外,我自己添加的(,我怀疑讲师犯了一个错误,这就是为什么某些东西没有在应该的地方通过的原因。 但是我不知道它会是什么,因为我是 redux 的菜鸟。

感谢您的帮助!

查看此行:

authInputChange({'field': 'email', 'value:': text})

value:设置为等于text而不是value。所以你想要:

authInputChange({'field': 'email', 'value': text})

另外,我假设您的减速器设置正确。

旁注:这也是为什么我不喜欢在我的对象键周围加上引号。如果您没有在value:周围加上引号,您将立即看到此错误。

最新更新