What I did is I fetch a single data from database and created a component wherein I can edit the user’s input, but I’ve got a warning from typescript wherein I get this.
Property ‘title’ does not exist on type ‘{ error: string; }’.ts(2339)
This is my zod schema.
const formSchemaData = z.object({
title: z.string().min(2, {
message: "title must be at least 2 characters.",
}),
email: z.string().min(2, {
message: "email must be at least 2 characters.",
}).email(),
//other code
})
export type Events = z.infer<typeof formSchemaData>
const { data, error, isFetching } = useQuery({
queryKey: ["eventId", eventId],
queryFn: async () => await getDataById(eventId),
});
const form = useForm<Events>({
resolver: zodResolver(formSchemaData),
});
return (
<Form {...form}>
<form>
<FormField
control={form.control}
name="title"
defaultValue={data ? data.title : ''}
render={({ field }) => (
<FormItem>
<FormLabel>Title</FormLabel>
<FormControl>
<Input
placeholder="title"
{...field} />
</FormControl>
<FormDescription>
This is your public display name.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
)