Reactjs 如何从reducer中的redux表单访问值?

Reactjs 如何从reducer中的redux表单访问值?,reactjs,redux,react-redux,redux-form,Reactjs,Redux,React Redux,Redux Form,我试图从reducer中填写的redux表单中获取访问权限,以便将另一个对象的值替换为数组。如何正确提交和传递redux表单中的值 我试着通过redux操作将其传递回去。我试着直接从商店在reducer中访问它,因为我想那就是它存储的地方。我觉得我做错了什么 class EditWorkoutItem extends Component { state = { open: false }; // Opens the page handleClickOpen = () =

我试图从reducer中填写的redux表单中获取访问权限,以便将另一个对象的值替换为数组。如何正确提交和传递redux表单中的值

我试着通过redux操作将其传递回去。我试着直接从商店在reducer中访问它,因为我想那就是它存储的地方。我觉得我做错了什么

class EditWorkoutItem extends Component {
  state = {
    open: false
  };

  // Opens the page
  handleClickOpen = () => {
    this.props.loadData(this.props.id);
    this.setState({ open: true });
  };

  // Cancels the changes and closes the page
  handleClose = () => {
    this.setState({ open: false });
  };

  // Passes back the id to the parent so the correct item can be replaced.
  // Passes back the new workout list
  handleSubmitChanges = e => {
    e.preventDefault();
    this.props.editWorkout(this.props.id); // this passes the workouts id back
    this.setState({ open: false });
  };

  render() {
    return (
      <>
        <Button
          color="primary"
          size="small"
          disableRipple
          onClick={this.handleClickOpen}
        >
          edit
        </Button>
        <Dialog
          open={this.state.open}
          onClose={this.handleClose}
          style={styles.dialog}
          fullScreen
        >
          <DialogTitle>Edit This Workout</DialogTitle>
          <form onSubmit={this.props.handleSubmit} style={styles.form}>
            <DialogContent>
              <Field
                name="date"
                component={DatePicker}
                format={null}
                hintText="Date Of Workout"
                fullWidth={true}
                locale="en-US"
              />
              <Field
                name="name"
                component={TextField}
                floatingLabelText="Workout Name"
                style={styles.textfield}
              />
              <Field
                name="duration"
                type="number"
                component={TextField}
                floatingLabelText="Estimated Duration"
                style={styles.textfield}
              />
              <FieldArray name="exercises" component={renderExercises} />
            </DialogContent>
            <DialogActions>
              <Button
                color="primary"
                type="submit"
                onClick={this.handleSubmitChanges} //Submitted here
              >
                Submit Changes
              </Button>
              <Button onClick={this.handleClose}>Cancel</Button>
            </DialogActions>
          </form>
        </Dialog>
      </>
    );
  }
}


无论我做什么,值都不会到达减速器。任何帮助都将不胜感激

您是否曾尝试使用
mapDistchpathToProps
在类
EditWorkUtiItem
中分派操作,如下所示:

const connectToRedux = connect(null, 
   dispatch => ({
       handleSubmitChanges: values => {
           // values here is all value of your form
           console.log(values);
           dispatch({ type: "EDIT_WORKOUT", payload: values }) // dispatch an action with
           // type is EDIT_WORKOUT and payload is all value of Redux-form
       }
   })
)
调用
handleSubmitChanges
,格式为:

<form onSubmit={this.props.handleSubmitChanges} style={styles.form}>
...
...
<Button
   color="primary"
   type="submit"
   // onClick={this.handleSubmitChanges} // remove this
>

您是否在任何时候发送“编辑训练”操作?是的,当我按submit时,handleSubmitChanges在您指定的位置被调用,但在我提交表单后它没有更改列表…它看起来很刷新,因为删除对常规handleSubmitChanges函数的onClick意味着它没有e.preventDefault()。它也无法将id传递回我试图更改的对象
<form onSubmit={this.props.handleSubmitChanges} style={styles.form}>
...
...
<Button
   color="primary"
   type="submit"
   // onClick={this.handleSubmitChanges} // remove this
>
case "EDIT_WORKOUT":
   console.log(action.payload) // You can receive values of Redux-form here
   return;