Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't seem to render <FormItem > as a children of <FieldArray /> #148

Open
thomasfaller opened this issue Jun 17, 2020 · 1 comment
Open

Comments

@thomasfaller
Copy link

thomasfaller commented Jun 17, 2020

Hey guys,
I'm experiencing some issues using Formik alongside Ant Design. I'm using formik-antd package to make that easier and I'm just stumbling on getting what I want from the <FieldArray /> component.

I'd like to leverage the Ant-Design components, using <FormItem> alongside <Input> to get proper labelling of my fields.

The problem is that I can't seem to invoke/use inside the FieldArray render method.
To sum it up, the following works:

<Form>
  <FieldArray
    name="patients"
      render={() => (
        <div>
          {props.values.patients.map((patient, i) => (
            <div key={i}>
              <Input name={`patients[${i}].firstName`} />
              <Input name={`patients[${i}].lastName`}></Input>
              <Input name={`patients[${i}].items`}></Input>
            </div>
          ))}
        </div>
      )}
    />

but the following doesn't :

<Form>
  <FieldArray
    name="patients"
      render={() => (
        <div>
          {props.values.patients.map((patient, i) => (
            <div key={i}>
              <FormItem label="first name">
                <Input name={`patients[${i}].firstName`} />
              </FormItem>
              <Input name={`patients[${i}].lastName`}></Input>
              <Input name={`patients[${i}].items`}></Input>
            </div>
          ))}
        </div>
      )}
    />

When I try to implement that, I get the following error from React 😫

Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.
@jannikbuschke
Copy link
Owner

jannikbuschke commented Jun 17, 2020

Can you use the FormItem (or Form.Item) component from formik-and and pass in the same name prop. I.e.

<FormItem label="first name" name={`patients[${i}].firstName`}>
  <Input name={`patients[${i}].firstName`} />
</FormItem>

and report if this works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants