Skip to content

Commit

Permalink
feat: make useFormMetadata accept no formId (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung authored Apr 1, 2024
1 parent dda3f63 commit ac3a9a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/conform-react/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function useFormMetadata<
Schema extends Record<string, any>,
FormError = string[],
>(
formId: FormId<Schema, FormError>,
formId?: FormId<Schema, FormError>,
options: {
defaultNoValidate?: boolean;
} = {},
Expand Down
19 changes: 8 additions & 11 deletions playground/app/routes/subscription.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
type FieldName,
type FormId,
type FieldMetadata,
type FormMetadata,
getFormProps,
Expand Down Expand Up @@ -72,13 +71,13 @@ export default function Example() {
const message = fields.message.name;
const description = (
<ul className="space-y-1 list-disc">
<FormMetadata strict={strict} formId={form.id} subject="initialValue" />
<FormMetadata strict={strict} formId={form.id} subject="value" />
<FormMetadata strict={strict} formId={form.id} subject="key" />
<FormMetadata strict={strict} formId={form.id} subject="dirty" />
<FormMetadata strict={strict} formId={form.id} subject="valid" />
<FormMetadata strict={strict} formId={form.id} subject="errors" />
<FormMetadata strict={strict} formId={form.id} subject="allErrors" />
<FormMetadata strict={strict} subject="initialValue" />
<FormMetadata strict={strict} subject="value" />
<FormMetadata strict={strict} subject="key" />
<FormMetadata strict={strict} subject="dirty" />
<FormMetadata strict={strict} subject="valid" />
<FormMetadata strict={strict} subject="errors" />
<FormMetadata strict={strict} subject="allErrors" />
<FieldMetadata strict={strict} name={name} subject="initialValue" />
<FieldMetadata strict={strict} name={name} subject="value" />
<FieldMetadata strict={strict} name={name} subject="key" />
Expand Down Expand Up @@ -153,16 +152,14 @@ const FieldMetadata = memo(function FieldMetadata({
});

const FormMetadata = memo(function FormMetadata({
formId,
subject,
strict,
}: {
formId: FormId;
subject: keyof FormMetadata<Record<string, any>>;
strict: boolean;
}) {
const renderCount = useRenderCount(strict);
const form = useFormMetadata(formId);
const form = useFormMetadata();

// eslint-disable-next-line no-console
console.log(`form.${subject}: ${JSON.stringify(form[subject])}`);
Expand Down

0 comments on commit ac3a9a0

Please # to comment.