Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update resolver examples to use inference. Improve highlighting. #1155

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

Merged
bluebill1049 merged 2 commits into react-hook-form:master from colinhacks:fix/update-examples
Jun 9, 2025

Conversation

Copy link
Contributor

@colinhacks colinhacks commented Jun 9, 2025
edited
Loading

  • Updated resolver examples to avoid unnecessary generics now that the resolvers all support inference
  • Changed some codeblocks to lang=tsx to slightly improve syntax highlighting

Before:
Screenshot 2025年06月09日 at 12 37 51

After:
Screenshot 2025年06月09日 at 12 37 40

Copy link

vercel bot commented Jun 9, 2025
edited
Loading

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 Jun 9, 2025 8:07pm

Copy link

netlify bot commented Jun 9, 2025
edited
Loading

Deploy Preview for sage-cassata-31d224 ready!

Name Link
🔨 Latest commit 04007ed
🔍 Latest deploy log https://app.netlify.com/projects/sage-cassata-31d224/deploys/68473ef352698d0008d3acd8
😎 Deploy Preview https://deploy-preview-1155--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.

@@ -464,7 +459,7 @@ const schema = yup
.required()

const App = () => {
const { register, handleSubmit } = useForm<Inputs>({
const { register, handleSubmit } = useForm({
Copy link
Contributor Author

@colinhacks colinhacks Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested to ensure this works 👍

return (
<form onSubmit={handleSubmit(onSubmit)}>
<form onSubmit={handleSubmit((data) => {
Copy link
Contributor Author

@colinhacks colinhacks Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that the inline onSubmit is 100% inferred (no z.infer<> calls) but I can change this back if you prefer an independently defined onSubmit

resolver: zodResolver(FormSchema),
defaultValues: {
username: "",
},
})

function onSubmit(data: z.infer<typeof FormSchema>) {
function onSubmit(data: z.output<typeof FormSchema>) {
Copy link
Contributor Author

@colinhacks colinhacks Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to gently point people towards z.output and z.input. z.infer is equivalent to z.output but I think it's better to be explicit, especially for RHF where the distinction matters quite a lot.

bluebill1049 reacted with thumbs up emoji
Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks collin!

@bluebill1049 bluebill1049 merged commit 8cc05b4 into react-hook-form:master Jun 9, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@bluebill1049 bluebill1049 bluebill1049 approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /