如何防止 React-Final-Form 在用户提交表单后重置表单值?

How to prevent React-Final-Form to reset the form values after user submits the form?

我在 React App 中使用 react-final-form。效果很好!

但是有什么方法可以防止 react-final-form 在用户成功提交表单后重置表单的输入值。

我需要它的原因是,目前当用户在提交表单后被重定向时,用户看到输入值被重置为 200-400 micro second 在提交表单和重定向到其他操作之间的初始表单值组件。

我尝试使用以下但没有用:

e.preventDefault();

return false;

以下是处理表单提交的函数。

export const useCreateAgent = (
  onCompleted: () => void,
) => {
  const [createAgent] = useMutation(CREATE_AGENT, {
    onCompleted,
  });

  return useCallback(async (agent: IAgent) => {
    try {
      await createAgent(createVariables({ ...agent }));
    } catch (errors) {
      return errors;
    }
  }, [createAgent]);
}

如果只是提交和新页面之间的外观问题:

event.persist() 阻止 React 重置事件对象。

keepDirtyOnReinitialize 道具修复了该问题。

<Form keepDirtyOnReinitialize >
   ...
</Form>