Skip to content

v1 How to pass formFieldSet to components? #442

Answered by edmundhung
jmaldon1 asked this question in Q&A
Discussion options

You must be logged in to vote

Two approaches:

// 1. Pass the form metadata down and grab the fieldset from the form
import { type FormMetadata, useForm } from '@conform-to/react';

function Container() {
  const [form] = useForm();

  return (
    <Component form={form} />
  );
}

function Component({ form }: { form: FormMetadata<Schema> }) {
  const fieldset = form.getFieldset();

  // ...
}

// 2. Pass the name down and call the useField hook if you use FormProvider
import { type FieldName, FormProvider, useForm, useField } from '@conform-to/react';

function Container() {
  const [form] = useForm();

  return (
    <FormProvider context={form.context}>
      <Component name={form.name} />
    </FormProvider>
  );
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jmaldon1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants