Skip to content

Commit

Permalink
adjust schema setup
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Sep 28, 2023
1 parent 6948572 commit 9bc05f8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions docs/complex-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,14 @@ import { parse } from '@conform-to/zod';
import { useRef } from 'react';
import { z } from 'zod';

const schema = z.object({
tasks: z.array(
z.object({
title: z.string(),
notes: z.string(),
})
),
const todoSchema = z.object({
title: z.string(),
notes: z.string(),
});

type Todo = z.infer<typeof schema>['tasks'][number];
const schema = z.object({
tasks: z.array(todoSchema),
});

function Example() {
const [form, { tasks }] = useForm({
Expand All @@ -156,7 +154,11 @@ function Example() {
);
}

function TodoFieldset({ config }: { config: FieldConfig<Todo> }) {
function TodoFieldset({
config,
}: {
config: FieldConfig<z.infer<typeof todoSchema>>;
}) {
const ref = useRef<HTMLFieldSetElement>(null);
// Both useFieldset / useFieldList accept form or fieldset ref
const { title, notes } = useFieldset(ref, config);
Expand All @@ -170,5 +172,4 @@ function TodoFieldset({ config }: { config: FieldConfig<Todo> }) {
</fieldset>
);
}

```

0 comments on commit 9bc05f8

Please sign in to comment.