Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

javascript - React Final Form Error: Must specify either a render prop

I am trying to build a simple form with React-Final-Form like this:

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;

The TextInputNew Component is this:

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;

Then I got this error when I use this NewUIForm component

Error: Must specify either a render prop, a render function as children, or a component prop to ReactFinalForm

By the way, the UI framework is Fluent-UI Can anyone help me? Thanks!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're second <Form> should be <form>.

    <form onSubmit={handleSubmit}>
      <Field name="email" component={TextInputNew} />
      <Field name="email" component={TextInputNew} />
      <PrimaryButton type='submit' text="Save" />
    </form>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...