我有一个向导表单,用于创建和更新表单。我正在使用redux-form/immutable

当我从向导表单的tab1导航到tab2时,我失去了表单的tab1中的状态(用户输入)

我尝试使用destroyOnUnmount: false
没有forceUnregisterOnUnmount: falseenableReinitialize: true在更新屏幕上工作正常,但是对于创建屏幕,在这种情况下,我无法使用从API获取的现有值来初始化表单。

FUNCTIONAL FORM COMPONENT

const AlphaForm = () => {

  return (
    <Panel theme="light">
      <PanelHeader>FORM</Panel.Header>
      <PanelBody>
        <Field
          component={Check}
          label="abc"
          name="abc"
          type="checkbox"
        />
        .....................................
      </PanelBody>
    </Panel>
  );
};


Wrapper

let AlphaFormWrapper = reduxForm({
  destroyOnUnmount: false,
  forceUnregisterOnUnmount: false,
  enableReinitialize: true,
  form: 'alphaForm'
})(AlphaForm);


Connect

const AlphaConnect = connect(
  state => {
    return {
      initialValues: state.getIn(['alphaForm'])
    };
  },
)(AlphaFormWrapper);

最佳答案

enableReinitialize: true一起使用keepDirtyOnReinitialize: true为我解决了上述问题

10-06 00:45