Replies: 2 comments
-
Related to this, I'm hoping this proposal is considered so that we can have automatic validation and prop binding just by defining a zod schema on the route, without requiring api changes. With this, your code would be simplified to: export const schema = z.object({
title: z.string().min(10).max(30),
email: z.string().email(),
content: z.string().max(40),
});
export const action = async ({ data }: DataFunctionArgs<typeof schema>) => {
await db.feedback.create({ data });
await sendFeedback(data);
return { success: true };
}; |
Beta Was this translation helpful? Give feedback.
-
I doubt the team want to enforce Zod as The Way to validate request bodies instead of allowing teams to use any tool for that. Also doing export const FormDataEntryValueSchema = z
.union([z.string(), z.instanceof(File)])
.nullable();
export function formData() {
return z.instanceof(FormData).transform((formData) => {
let entries: Array<[string, FormDataEntryValue | FormDataEntryValue[]]> =
[];
for (let key of formData.keys()) {
let value = formData.getAll(key);
if (isEmpty(value)) continue;
if (value.length === 1) entries.push([key, value[0]]);
else entries.push([key, value]);
}
return z
.array(
z.tuple([
z.string(),
FormDataEntryValueSchema.or(FormDataEntryValueSchema.array()),
])
)
.transform((entries) => Object.fromEntries(entries))
.parse(entries);
});
} Then I do this: let body = formData().pipe(schema).parse(await request.formData()) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I used qwikjs for a while before, which use vite as same as remix. it has some features provided good DX. Would remix consider adding some of those features?
for example, it use
zod
to verify form data types, it has two advantages:If remix considering add this feature, maybe can write like this:
The closest proposal with this feature I've seen is this: #5383
At that time, it was not promoted because of the compiler, but now that the compiler has been changed to vite, this proposal may be realized. like this:
Beta Was this translation helpful? Give feedback.
All reactions