I used the appwrite cli to get types such as:
export type Events = Models.Row & {
title: string;
description: string | null;
startDate: string;
endDate: string;
location: string;
I then derived the zod schema like this:
export const eventFormSchema = z.object({
title: z.string().min(1, "Event Titel ist erforderlich"),
description: z.string().nullish(),
startDate: z.string().min(1, "Startdatum ist erforderlich"),
endDate: z.string().min(1, "Enddatum ist erforderlich"),
location: z.string().min(1, "Ort ist erforderlich")
});
so that I can do:
// ... some imports
type EventFormData = z.infer<typeof eventFormSchema>;
export function EventForm({ event, eventId, type = "create" }: EventFormProps) {
const eventFn = useServerFn(
type === "create" ? eventsService.createEvent : eventsService.updateEvent
);
// ... other code
const form = useForm({
defaultValues: {
title: event?.title || "",
description: event?.description || undefined,
startDate: event?.startDate
? new Date(event.startDate).toISOString().split("T")[0]
: "",
endDate: event?.endDate
? new Date(event.endDate).toISOString().split("T")[0]
: "",
location: event?.location || "",
status: event?.status || "draft",
bookingLink: event?.bookingLink || undefined,
imageUrl: event?.imageUrl || undefined,
} as EventFormData
// ...other code
return (
// ... form elements
<form.Field
name="description"
// ... some other code
<Textarea
id={field.name}
name={field.name}
value={field.state.value} // shows Type 'null' is not assignable to type // 'string | number | readonly string[] | undefined'.ts(2322)
/>
//... other code
)
}
I am really a bit lost how to properly set this up. This null value is killing me.
Try replacing value={field.state.value} with value={field.state.value ?? ""} first. See whether it works
Recommended threads
- Auth not working on expo react native
I'm trying to launch a development server with expo go and appwrite as a backend. On my windows pc, I've got a local docker instance of appwrite running as my b...
- createMembership is not sending email wi...
Parameters should be correct. Account and Membership are successfully created. I have a next.js project with localhost origin allowed. I checked spam etc. i...
- Bulk delete failed with 401
- I created a transaction to bulk delete rows in a table has `done` equal `true` follow documentation. But when run, it returns 401 unauthorized error as screen...