Skip to content

docs: Add SubmitErrorHandler to typescript example so it matches the javascript example #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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

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 Apr 30, 2025 11:20am

Copy link

netlify bot commented Apr 30, 2025

Deploy Preview for sage-cassata-31d224 ready!

Name Link
🔨 Latest commit f076378
🔍 Latest deploy log https://app.netlify.com/sites/sage-cassata-31d224/deploys/6812074a1480f800081598dc
😎 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 site configuration.

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.

1 participant