1

我正在尝试使用React-Final-Form构建一个简单的表单,如下所示:

import * as React from "react";
import {
  PrimaryButton,
} from "office-ui-fabric-react/lib/Button";
import { Form , Field } from "react-final-form";
import { FORM_ERROR } from "final-form";
import { IUserFormValues } from "../../models/user";
import { RootStoreContext } from "../../stores/rootStore";
import TextInputNew from "./TextInputNew";

const NewUIForm = () => {
  const rootStore = React.useContext(RootStoreContext);
  const { login } = rootStore.userStore;
  return (
    <Form
      onSubmit={(values: IUserFormValues) =>
        login(values).catch((error) => ({
          [FORM_ERROR]: error,
        }))
      }

      render={({
        handleSubmit,

      }) => (
        <Form onSubmit={handleSubmit}>
          <Field name="email" component={TextInputNew} />
          <Field name="email" component={TextInputNew} />
          <PrimaryButton type='submit' text="Save" />
        </Form>
      )}
    />
  );
};
export default NewUIForm;

TextInputNew组件是这样的:

import * as React from "react";
import { TextField } from "office-ui-fabric-react/lib/TextField";
import { FieldRenderProps } from "react-final-form";

interface IProps extends FieldRenderProps<string, HTMLInputElement> {}

const TextInputNew: React.FC<IProps> = ({ input }) => {
  return (
    <div>
      <input {...input} />
      <TextField label="Standard" />
    </div>
  );
};
export default TextInputNew;

然后我在使用这个NewUIForm组件时遇到了这个错误

错误:必须将渲染道具、渲染函数指定为子级或组件道具到 ReactFinalForm

顺便说一句,UI框架是Fluent-UI 有人能帮帮我吗?谢谢!!

4

2 回答 2

1

<Form>应该是第二个<form>

    <form onSubmit={handleSubmit}>
      <Field name="email" component={TextInputNew} />
      <Field name="email" component={TextInputNew} />
      <PrimaryButton type='submit' text="Save" />
    </form>
于 2021-01-01T10:17:57.897 回答
1

对于可能遇到此模糊错误消息的其他任何人,问题是 <Form> 的渲染功能出现问题。

对于 OP,它在 <Form> 内使用了错误的表单标签。对我来说,这是 <Field> 组件上的一个拼写错误的属性(components={MyComponent},哎呀)。

由于错误可能由多种原因引起,并且消息不是很具体,因此可以通过浏览器调试器了解问题可能出在哪里,在我的情况下,它看起来像这样:

浏览器堆栈跟踪

于 2021-03-05T21:40:46.103 回答