Replies: 2 comments 1 reply
-
The Can you share your zod schema here? |
Beta Was this translation helpful? Give feedback.
-
I have similar issue. Code looks something like that: import { z } from "zod";
import { getZodConstraint, parseWithZod } from '@conform-to/zod'
import { ActionFunctionArgs } from "@remix-run/node";
import {useForm} from "@conform-to/react"
import { Form, useActionData } from "@remix-run/react";
const schema = z.object({
email: z.string().email(),
password: z.string().min(6),
});
const constraint = getZodConstraint(schema);
export async function action({request}: ActionFunctionArgs) {
// action
}
export default function SignUp() {
const lastResult = useActionData<typeof action>();
const [form, fields] = useForm({
lastResult,
constraint,
// onValidate({ formData }) {
// return parseWithZod(formData, { schema })
// }
});
const test = fields. // I only have field suggestions here with `onValidate`
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<p>Sign Up</p>
// <Form />
</div>
);
} Isn't it more straightforward for types to be enforced with just the constraint, since it has access to the zod schema? Also, if I understand it correctly (not 100% sure after reading the docs), |
Beta Was this translation helpful? Give feedback.
-
This might've been asked before, but I couldn't find any previous discussions via search. I was following the initial guide to using conform and was pretty surprised that the value of
fields
, in code likeIs untyped. I would kind of expect this to be able to mirror the fields that zod is expecting for form data, even if it requires a little handholding. It looks like
useForm
is generic and can take a schema, but the examples don't showcase this at all. Maybe I'm missing something about the intended way to useuseForm
?Beta Was this translation helpful? Give feedback.
All reactions