v1 How to pass formFieldSet
to components?
#442
-
We used to have the import type { Fieldset } from "@conform-to/react";
type ComponentProps = {
formFieldset: Fieldset<Schema>;
required?: boolean;
};
function Container() {
const [form, formFieldset] = useForm<Schema>({
lastResult,
});
return (<Box>
<Component formFieldset={formFieldset} />
</Box>)
} But now |
Beta Was this translation helpful? Give feedback.
Answered by
edmundhung
Feb 9, 2024
Replies: 1 comment
-
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>
);
}
function Component({ name }: { name: FieldName<Schema> }) {
const [meta] = useField(name);
const fieldset = meta.getFieldset();
// ...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jmaldon1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two approaches: