Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
2 replies
Xaohs

Anyone can help me with this React-Hook-Form problem?

Hi, i'm creating a complex form-system using React-Hook-Form, but my handleSubmit's from RHF are not firing for some reason. I have stripped my code down to the bare minimum, and it's still not functioning, is there something I am missing??

The only thing firing off is the console.log("submitting..") but the actual data/errors of the form are not.
    const form = useForm<TFormValues>({
        resolver: zodResolver(FormSchema),
        defaultValues,
    });
return (
 <form
        onSubmit={(e) => {
            e.preventDefault();
            console.log("Submitting...");
            form.handleSubmit(
                (data) => {
                    console.log(data);
                },
                (errors) => {
                    console.log(errors);
                }
            );
        }}
    >
        <input type='text' {...form.register('testName')} />
        <input type='submit' />
    </form>


Calling form.handleSubmit() programatically will also not work, outside of the event handler itself, so I am unsure where this issue is arising from
Was this page helpful?