Reactjs redux表单更新状态和检索

Reactjs redux表单更新状态和检索,reactjs,react-redux,jsx,redux-form,Reactjs,React Redux,Jsx,Redux Form,我有两个redux表单组件,第一个是LoginFormComponent,它是一个redux表单,表单名为“submitValidation” LoginFormComponent=reduxForm({ 表格:“提交验证” })(LoginFormComponent) 此表单组件具有如下输入字段:- 在表单提交时,我想导航到第二个redux表单组件,它是VerifyLoginBodyComponent,并希望在div中显示第一个组件提交的“userid”,如下所示:- 您正在以以下身份

我有两个redux表单组件,第一个是LoginFormComponent,它是一个redux表单,表单名为“submitValidation

LoginFormComponent=reduxForm({
表格:“提交验证”
})(LoginFormComponent)
此表单组件具有如下输入字段:-


在表单提交时,我想导航到第二个redux表单组件,它是VerifyLoginBodyComponent,并希望在div中显示第一个组件提交的“userid”,如下所示:-


您正在以以下身份登录:{userid}
这就是我在第一个表单组件中处理提交的方式

类LoginFormComponent扩展组件{
建造师(道具){
超级(道具);
this.submit=this.submit.bind(this);
}
提交(价值观){
log(JSON.stringify(values));
this.context.router.push('/verify');
}
render(){
const{handleSubmit}=this.props
返回(
)
}
LoginFormComponent=reduxForm({
表格:“提交验证”
})(LoginFormComponent)
导出默认LoginFormComponent;
这是我的redux商店:

const初始应用程序状态={
表格:{
提交验证:{
用户标识:“”
}
}
};
如何从VerifyLoginBodyComponent中的LoginFormComponent访问提交的用户ID

我检查了,和,但仍然无法在第二个表单组件中显示用户ID


请提供任何建议。

redux form
提供可用于创建从redux存储中检索表单值的选择器。您可以在
VerifyLoginBodyComponent的
MapStateTrops
函数中使用该选项

例如:

const selector = formValueSelector('submitValidation')

const mapStateToProps = reducers => {
  const signingInUserId = selector(reducers, 'userid')
  return { signingInUserId }
}
这当然取决于表单值在提交成功后才从存储中清除的事实


希望这有帮助!

redux form
提供可用于创建从redux存储检索表单值的选择器。您可以在
VerifyLoginBodyComponent
MapStateTrops
-函数中使用该选择器

例如:

const selector = formValueSelector('submitValidation')

const mapStateToProps = reducers => {
  const signingInUserId = selector(reducers, 'userid')
  return { signingInUserId }
}
这当然取决于表单值在提交成功后才从存储中清除的事实


希望这有帮助!

谢谢你的建议@jake。我试过了,但没有成功。我试过了“state”,而不是代码中的“reducer”还有,但那也不起作用。我必须使用传统的mapDispatchToProps=>dispatch an action=>reducer和update state才能使它起作用。我想知道redux表单一定有一些好处,可以让我减少编码。@Jake-有没有办法确保表单值在提交成功之前不会从存储中清除?W我的意思是,除非您卸载表单,否则我相当肯定这些值会一直保存在存储中,直到提交成功。谢谢您的建议@jake。我尝试了它,但没有成功。我尝试了“state”,而不是代码中的“reducer”还有,但那也不起作用。我必须使用传统的mapDispatchToProps=>dispatch an action=>reducer和update state才能使它起作用。我想知道redux表单一定有一些好处,可以让我减少编码。@Jake-有没有办法确保表单值在提交成功之前不会从存储中清除?W我的意思是,除非您卸载表单,否则在提交成功之前,我相当肯定这些值会一直保存在存储中。