| 5 | new Promise<T>((res) => setTimeout(() => res(data), ms)); |
| 6 | |
| 7 | function DefaultValues() { |
| 8 | const { register } = useForm({ |
| 9 | defaultValues: async () => |
| 10 | sleep( |
| 11 | { |
| 12 | test: 'test', |
| 13 | checkbox: ['1', '2'], |
| 14 | test1: { |
| 15 | firstName: 'firstName', |
| 16 | lastName: ['lastName0', 'lastName1'], |
| 17 | deep: { |
| 18 | nest: 'nest', |
| 19 | }, |
| 20 | }, |
| 21 | }, |
| 22 | 10, |
| 23 | ), |
| 24 | }); |
| 25 | const [show, setShow] = React.useState(true); |
| 26 | |
| 27 | return ( |
| 28 | <> |
| 29 | {show ? ( |
| 30 | <form> |
| 31 | <input {...register('test')} /> |
| 32 | <input {...register('test1.firstName')} /> |
| 33 | <input {...register('test1.deep.nest')} /> |
| 34 | <input {...register('test1.deep.nest')} /> |
| 35 | <input {...register('test1.lastName.0')} /> |
| 36 | <input {...register('test1.lastName.1')} /> |
| 37 | <input type="checkbox" value={'1'} {...register('checkbox')} /> |
| 38 | <input type="checkbox" value={'2'} {...register('checkbox')} /> |
| 39 | </form> |
| 40 | ) : null} |
| 41 | <button type={'button'} id={'toggle'} onClick={() => setShow(!show)}> |
| 42 | toggle |
| 43 | </button> |
| 44 | </> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | export default DefaultValues; |