@@ -25,23 +25,23 @@ $ npm install @hookform/use-typed-controller
2525## Quickstart
2626
2727``` tsx
28- import { useTypedController } from " @hookform/use-typed-controller" ;
29- import { useForm } from " react-hook-form" ;
30- import { TextField , Checkbox } from " @material-ui/core" ;
28+ import { useTypedController } from ' @hookform/use-typed-controller' ;
29+ import { useForm } from ' react-hook-form' ;
30+ import { TextField , Checkbox } from ' @material-ui/core' ;
3131
3232type FormValues = {
33- flatType : string ;
33+ flat : string ;
3434 nested: {
35- objectType : { test: string };
36- arrayType : { test: boolean }[];
35+ object : { test: string };
36+ array : { test: boolean }[];
3737 };
3838};
3939
4040export default function App() {
4141 const { control, handleSubmit } = useForm <FormValues >();
4242 const TypedController = useTypedController <FormValues >({ control });
4343
44- const onSubmit = handleSubmit ((data ) => console .log (data );
44+ const onSubmit = handleSubmit ((data ) => console .log (data )) ;
4545
4646 return (
4747 <form onSubmit = { onSubmit } >
@@ -53,37 +53,29 @@ export default function App() {
5353
5454 <TypedController
5555 as = " textarea"
56- name = { [" nested" , " objectType " , " test" ]}
56+ name = { [' nested' , ' object ' , ' test' ]}
5757 defaultValue = " "
5858 rules = { { required: true }}
5959 />
6060
6161 <TypedController
62- name = { [" nested" , " arrayType " , 0 , " test" ]}
62+ name = { [' nested' , ' array ' , 0 , ' test' ]}
6363 defaultValue = { false }
6464 render = { (props ) => <Checkbox { ... props } />}
6565 />
6666
6767 { /* ❌: Type '"notExists"' is not assignable to type 'DeepPath<FormValues, "notExists">'. */ }
68- <TypedController
69- as = " input"
70- name = " notExists"
71- defaultValue = " "
72- />
68+ <TypedController as = " input" name = " notExists" defaultValue = " " />
7369
74- { /* ❌: Type '(string | number)[] ' is not assignable to type 'DeepPath<FormValues, ["nested", "objectType", 0, "notExists"]> '. */ }
70+ { /* ❌: Type 'number' is not assignable to type 'string | undefined '. */ }
7571 <TypedController
7672 as = " input"
77- name = { [" nested" , " objectType " , 0 , " notExists" ]}
73+ name = { [' nested' , ' object ' , 0 , ' notExists' ]}
7874 defaultValue = " "
7975 />
8076
8177 { /* ❌: Type 'true' is not assignable to type 'string | undefined'. */ }
82- <TypedController
83- as = " input"
84- name = " flatType"
85- defaultValue = { true }
86- />
78+ <TypedController as = " input" name = " flat" defaultValue = { true } />
8779
8880 <input type = " submit" />
8981 </form >
0 commit comments