@@ -445,16 +445,11 @@ npm install @hookform/resolvers
445
445
446
446
<TabGroup buttonLabels = { [" Yup" ," Zod" ," Joi" ," Ajv" ," Vest" , " Custom" ]} >
447
447
448
- ``` typescript copy sandbox="https://codesandbox.io/s/react-hook-form-apply-validation-ts-forked-nmbyh"
448
+ ``` tsx copy sandbox="https://codesandbox.io/s/react-hook-form-apply-validation-ts-forked-nmbyh"
449
449
import { useForm } from " react-hook-form"
450
450
import { yupResolver } from " @hookform/resolvers/yup"
451
451
import * as yup from " yup"
452
452
453
- type Inputs = {
454
- name: string
455
- age: string
456
- }
457
-
458
453
const schema = yup
459
454
.object ()
460
455
.shape ({
@@ -464,7 +459,7 @@ const schema = yup
464
459
.required ()
465
460
466
461
const App = () => {
467
- const { register, handleSubmit } = useForm < Inputs > ({
462
+ const { register, handleSubmit } = useForm ({
468
463
resolver: yupResolver (schema ), // yup, joi and even your own.
469
464
})
470
465
@@ -478,7 +473,7 @@ const App = () => {
478
473
}
479
474
```
480
475
481
- ``` typescript copy sandbox="https://codesandbox.io/s/react-hook-form-zod-resolver-ts-example-forked-w72vp"
476
+ ``` tsx copy sandbox="https://codesandbox.io/s/react-hook-form-zod-resolver-ts-example-forked-w72vp"
482
477
import { useForm } from " react-hook-form"
483
478
import { zodResolver } from " @hookform/resolvers/zod"
484
479
import * as z from " zod"
@@ -491,16 +486,15 @@ const schema = z.object({
491
486
type Schema = z .infer <typeof schema >
492
487
493
488
const App = () => {
494
- const { register, handleSubmit } = useForm < Schema > ({
489
+ const { register, handleSubmit } = useForm ({
495
490
resolver: zodResolver (schema ),
496
491
})
497
492
498
- const onSubmit = (data : Schema ) => {
499
- console .log (data )
500
- }
501
-
502
493
return (
503
- < form onSubmit = {handleSubmit(onSubmit )}>
494
+ <form onSubmit = { handleSubmit ((data ) => {
495
+ // handle inputs
496
+ console .log (data );
497
+ })} >
504
498
<input { ... register (" name" )} />
505
499
<input { ... register (" age" , { valueAsNumber: true })} type = " number" />
506
500
<input type = " submit" />
@@ -509,7 +503,7 @@ const App = () => {
509
503
}
510
504
```
511
505
512
- ``` typescript copy sandbox="https://codesandbox.io/s/react-hook-form-joiresolver-v6-ts-forked-5pseh"
506
+ ``` tsx copy sandbox="https://codesandbox.io/s/react-hook-form-joiresolver-v6-ts-forked-5pseh"
513
507
import { useForm } from " react-hook-form" ;
514
508
import { joiResolver } from " @hookform/resolvers/joi" ;
515
509
import Joi from " joi" ;
@@ -534,15 +528,15 @@ const App = () => {
534
528
535
529
return (
536
530
<form onSubmit = { handleSubmit (onSubmit )} >
537
- < input {... register ("name "} / >
538
- < input type = " number" {... register ("age "} / >
531
+ <input { ... register (" name" ) } />
532
+ <input type = " number" { ... register (" age" ) } />
539
533
<input type = " submit" />
540
534
</form >
541
535
);
542
536
}
543
537
```
544
538
545
- ``` javascript copy sandbox="https://codesandbox.io/s/react-hook-form-ajvresolver-vr3imc"
539
+ ``` tsx copy sandbox="https://codesandbox.io/s/react-hook-form-ajvresolver-vr3imc"
546
540
import { useForm } from " react-hook-form"
547
541
import { ajvResolver } from " @hookform/resolvers/ajv"
548
542
@@ -586,7 +580,7 @@ const App = () => {
586
580
}
587
581
```
588
582
589
- ``` javascript copy sandbox="https://codesandbox.io/s/vest-8q874"
583
+ ``` tsx copy sandbox="https://codesandbox.io/s/vest-8q874"
590
584
import * as React from " react"
591
585
import { useForm } from " react-hook-form"
592
586
import { vestResolver } from " @hookform/resolvers/vest"
@@ -633,7 +627,7 @@ const App = () => {
633
627
}
634
628
```
635
629
636
- ``` typescript copy sandbox="https://codesandbox.io/s/react-hook-form-customresoliver-ts-v7-juc63"
630
+ ``` tsx copy sandbox="https://codesandbox.io/s/react-hook-form-customresoliver-ts-v7-juc63"
637
631
import * as React from " react"
638
632
import { useForm } from " react-hook-form"
639
633
import * as Joi from " joi"
0 commit comments