question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useField must be used inside of a <Form> component

See original GitHub issue

Are you submitting a bug report or a feature request?

Bug

What is the expected behavior?

I am replacing redux-form with react-final-form in the process of upgrading in our apps react-admin v2 to v3.

<Field /> should be wrapped into <Form /> without error.

What is the current behavior?

It throw:

 useField must be used inside of a <Form> component

What’s your environment?

React Final Form version 6.3.5 Final Form version 4.18.7 OS/browser affected chrome Node version, 13.5

Other information

<SimpleForm
            redirect={redirect}
            toolbar={(
              <Toolbar redirect={redirect}>
                <SaveButton redirect={redirect} />
              </Toolbar>
            )}
            handleSubmit={this.handleSubmit}
            onSubmit={() => alert('submit')}
            record={record}
            submitOnEnter={false}
            {...rest}
          >
            <Wrapper>
              {list.map((siteService, i) => (
                <FormGroup key={siteService.name} check className={cn({ 'mt-5': !!i })}>
                  <Strong>
                    <Label check className="p-0">
                      <Field name="firstName" component="input" placeholder="First Name" />
                      <H2 className="d-inline-block">{siteService.name}</H2>
                    </Label>
                  </Strong>
                </FormGroup>
              ))}
            </Wrapper>
          </SimpleForm>

With <SimpleForm /> being https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/form/SimpleForm.js

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
abdelmomen1985commented, Oct 27, 2020

@kopax could you please tell how did you solve it using mutators , i am facing the same issu

0reactions
abrad45commented, Oct 4, 2020

@imryanjay useField must eventually bubble up to a <Form> component. That’s the solution to this issue. If you have code to share I can be more specific.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: useForm must be used inside of a <Form> component ...
I fixed this by adding react-final-form to my package JSON. For some reason webpack had an issue with it being a peer dependency...
Read more >
Final Form Docs – `useField()`
useField () returns FieldRenderProps . It will manage the rerendering of any component you use it in, i.e. the component will only rerender...
Read more >
Form - React-admin - Marmelab
It is a headless component used internally by <SimpleForm> , <TabbedForm> , and other form components. <Form> reads the record from the RecordContext...
Read more >
Advanced Usage - React Hook Form
Since most of us have to build forms with custom designs and layouts, it is our ... as a validation method, and to...
Read more >
Getting error trying to use use Storybook with react-admin ...
[Solved]-Getting error trying to use use Storybook with react-admin "useField must be used inside of a <Form> component"-Reactjs. Search. score:4.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found