Skip to content

Conversation

@faysvas
Copy link

@faysvas faysvas commented Apr 30, 2025

When browsing the docs I noticed that the TS and JS Sync examples in the docs for handleSubmit were mismatched.

Specifically, even though an onError handler is defined in the TS example, it isn't passed to handleSubmit.

handleSubmit(1)
handleSubmit(2)

Another idea might be to update both the javascript and typescript examples to include some validation rules, like this one

import React from "react"
import { useForm, SubmitHandler, SubmitErrorHandler } from "react-hook-form"

type FormValues = {
  firstName: string
  lastName: string
  email: string
}

export default function App() {
  const { register, handleSubmit } = useForm<FormValues>()
  const onSubmit: SubmitHandler<FormValues> = (data) => console.log(data)
  const onError: SubmitErrorHandler<FormValues> = (errors) => console.log(errors);

  return (
    <form onSubmit={handleSubmit(onSubmit, onError)}>
      <input {...register("firstName"), { required: true }} />
      <input {...register("lastName"), { minLength: 2 }} />
      <input type="email" {...register("email")} />

      <input type="submit" />
    </form>
  )
}

from the TS section

@vercel
Copy link

vercel bot commented Apr 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-hook-form-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 11:14pm

@netlify
Copy link

netlify bot commented Apr 30, 2025

Deploy Preview for sage-cassata-31d224 ready!

Name Link
🔨 Latest commit 1d0dd2e
🔍 Latest deploy log https://app.netlify.com/projects/sage-cassata-31d224/deploys/6882be087f2d260008f2d609
😎 Deploy Preview https://deploy-preview-1140--sage-cassata-31d224.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bluebill1049
Copy link
Member

sorry for the late review, looks like it's already been updated. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants