react-hook-form 7.18.0-next.0 → 7.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,1213 @@
1
+ # Changelog
2
+
3
+ ## [7.18.1] - 2021-11-02
4
+
5
+ - revert `FieldPathWithValue`
6
+
7
+ ## [7.18.0] - 2021-10-28
8
+
9
+ ## Added
10
+
11
+ - bring back `FieldPathWithValue`
12
+ - schema errors parent object look up
13
+
14
+ ```tsx
15
+ const validationSchema = object().shape({
16
+ questions: array().min(1, 'Array cannot be empty'),
17
+ });
18
+
19
+ // the above schema will be picked up by field array action
20
+ // the logic applies to group error object eg checkboxes
21
+ <button
22
+ type="button"
23
+ onClick={() => {
24
+ remove(questionIndex);
25
+ }}
26
+ >
27
+ Remove
28
+ </button>;
29
+ ```
30
+
31
+ ## [7.17.0] - 2021-10-02
32
+
33
+ ## Added
34
+
35
+ - new type `FieldPathWithValue` to improve generic components type support
36
+
37
+ ```tsx
38
+ type ExpectedType = { test: string };
39
+
40
+ const Generic = <FormValues extends FieldValues>({
41
+ name,
42
+ control,
43
+ }: {
44
+ name: FieldPathWithValue<FormValues, ExpectedType>;
45
+ control: Control<FormValues>;
46
+ }) => {
47
+ const {
48
+ field: { value, ...fieldProps },
49
+ } = useController<FormValues, ExpectedType>({
50
+ name,
51
+ control,
52
+ defaultValue: { test: 'value' },
53
+ });
54
+
55
+ return <input type="text" value={value.test} {...fieldProps} />;
56
+ };
57
+ ```
58
+
59
+ ## [7.16.1] - 2021-09-27
60
+
61
+ ## Changed
62
+
63
+ - `formState` subscription no longer subscribed at `useEffect` instead the execution of each hook
64
+
65
+ ## [7.16.0] - 2021-09-25
66
+
67
+ ## Added
68
+
69
+ - `register` allowed pass custom `onChange` and `onBlur`
70
+
71
+ ```tsx
72
+ <input
73
+ type="text"
74
+ {...register('test', {
75
+ onChange: (e) => {},
76
+ onBlur: (e) => {},
77
+ })}
78
+ />
79
+ ```
80
+
81
+ ## [7.15.0] - 2021-09-05
82
+
83
+ ## Added
84
+
85
+ - `useFieldArray` new method `replace()`
86
+
87
+ ```tsx
88
+ const { control } = useForm({
89
+ defaultValues: {
90
+ test: [{ value: 'lorem' }, { value: 'ipsum' }],
91
+ },
92
+ });
93
+ const { fields, replace } = useFieldArray({
94
+ control,
95
+ name: 'test',
96
+ });
97
+
98
+ const handleFullyReplacement = (): void => {
99
+ // remove old and set fully new values
100
+ replace([{ value: 'dolor' }, { value: 'sit' }, { value: 'amet' }]);
101
+ };
102
+ ```
103
+
104
+ - Improved to not map types defined with `interface`.
105
+
106
+ ```tsx
107
+ import { useForm } from 'react-hook-form';
108
+
109
+ interface CustomValue {
110
+ custom: string;
111
+ }
112
+
113
+ type FormValues = {
114
+ fieldName: CustomValue;
115
+ };
116
+
117
+ const { formState: errors } = useForm<FormValues>({
118
+ defaultValues: { fieldName: { custom: 'value' } },
119
+ });
120
+ ```
121
+
122
+ ## [7.14.0] - 2021-08-27
123
+
124
+ ## Added
125
+
126
+ - `register` add dependent validation
127
+
128
+ ```tsx
129
+ const App = () => {
130
+ const { register, getValues } = useForm();
131
+
132
+ return (
133
+ <form>
134
+ <input
135
+ {...register('firstName', {
136
+ validate: (value) => {
137
+ return getValues('lastName') === value;
138
+ },
139
+ })}
140
+ />
141
+ <input {...register('lastName', { deps: ['firstName'] })} /> // dependant validation
142
+ </form>
143
+ );
144
+ };
145
+ ```
146
+
147
+ ## [7.13.0] - 2021-08-22
148
+
149
+ ## Added
150
+
151
+ `Trigger`
152
+
153
+ - Trigger will enable object name trigger and field array name trigger
154
+
155
+ ```tsx
156
+ useFieldArray({ name: 'test' });
157
+
158
+ trigger('name'); // will trigger the whole field array to validate
159
+ ```
160
+
161
+ `register`
162
+
163
+ - added a `disabled` prop as an option to toggle input disable attribute
164
+ - register will be able to seek input DOM reference through the `ref` callback
165
+
166
+ ```tsx
167
+ register('test', { disabled: true }) // will set value to undefined and pass disabled down to the input attribute
168
+
169
+ <div {...register('test')}>
170
+ <input name="test" /> // this input will be registered
171
+ </div>
172
+ ```
173
+
174
+ `useWatch`
175
+
176
+ - added `disabled` prop to toggle the state subscription.
177
+
178
+ ```tsx
179
+ useWatch({ disabled: true }); // you toggle the subscription
180
+ ```
181
+
182
+ `useFormState`
183
+
184
+ - added `disabled` prop to toggle the state subscription.
185
+
186
+ ```tsx
187
+ useFormState({ disabled: true }); // you toggle the subscription
188
+ ```
189
+
190
+ `setValue`
191
+
192
+ - allow set value for non-registered inputs include nested object and array field.
193
+
194
+ ```tsx
195
+ <input {...register('test.0.firstName')} />
196
+
197
+ setValue('test', [{ firstName: 'bill' }, {firstName: 'kotaro}, {firstName: 'joris'}]) // this will works
198
+ ```
199
+
200
+ ## [7.12.0] - 2021-07-24
201
+
202
+ ## Added
203
+
204
+ - new `useForm` config `delayError`
205
+
206
+ ```tsx
207
+ useForm({
208
+ delayError: 500, // delay error appear with 500ms
209
+ });
210
+ ```
211
+
212
+ ## [7.11.0] - 2021-07-13
213
+
214
+ ## Added
215
+
216
+ - `update` method to update an field array inputs
217
+
218
+ ```tsx
219
+ const { update } = useFieldArray();
220
+
221
+ update(0, data); // update an individual field array node
222
+ ```
223
+
224
+ ## [7.10.0] - 2021-07-02
225
+
226
+ ## Changed
227
+
228
+ - `defaultValue` is no longer a required prop for register input with `useFieldArray`
229
+
230
+ ## [7.9.0] - 2021-06-19
231
+
232
+ ## Added
233
+
234
+ - new config at `useForm` to enabled native browser validation
235
+
236
+ ```tsx
237
+ const { register, handleSubmit } = useForm({
238
+ shouldUseNativeValidation: true,
239
+ });
240
+ ```
241
+
242
+ ## [7.8.5] - 2021-06-15
243
+
244
+ ### Change
245
+
246
+ - `useController` no longer access input `ref` except `focus` event for focus management
247
+
248
+ ## [7.8.0] - 2021-06-5
249
+
250
+ ### Added
251
+
252
+ - `setValue` support `shouldTouch` to update formState touchFields
253
+
254
+ ```tsx
255
+ setValue('firstName', 'value', { shouldTouch: true });
256
+ ```
257
+
258
+ - `register` now accept `value` as option
259
+
260
+ ```tsx
261
+ register('firstName', { value: 'value' });
262
+ ```
263
+
264
+ ## Changed
265
+
266
+ - `isValid` will initialise as `false`
267
+
268
+ ## [7.7.1] - 2021-05-30
269
+
270
+ ### Fixed
271
+
272
+ - `shouldUnregister: false` should not shallow merge or register absent input fields from `defaultValues`
273
+
274
+ ## [7.7.0] - 2021-05-29
275
+
276
+ ### Added
277
+
278
+ - `trigger` support focus with error input
279
+
280
+ ```ts
281
+ trigger('inputName', { shouldFocus: true });
282
+ ```
283
+
284
+ ### Changed
285
+
286
+ - `handleSubmit` will `throw` error within the onSubmit callback
287
+
288
+ ## [7.6.0] - 2021-05-15
289
+
290
+ ### Changed
291
+
292
+ - `useForm` will `register` missing inputs from `defaultValues`
293
+
294
+ ```tsx
295
+ const App = () => {
296
+ const { register, handleSubmit } = useForm({
297
+ defaultValues: {
298
+ test: { firstName: 'bill', lastName: 'luo' },
299
+ },
300
+ });
301
+
302
+ const onSubmit = (data) => {
303
+ // missing registered input will be included
304
+ console.log(data); // { test: { firstName: 'bill', lastName: 'luo' } }
305
+ };
306
+
307
+ return (
308
+ <form onSubmit={handleSubmit(onSubmit)}>
309
+ <input {...register('test.firstName')} />
310
+ <button />
311
+ </form>
312
+ );
313
+ };
314
+ ```
315
+
316
+ ## [7.5.0] - 2021-05-09
317
+
318
+ ### Changed
319
+
320
+ - `isSubmitSuccessful` will return false when `handleSubmit` callback failed with `Error` or `Promise` reject.
321
+ - unmounted input will no longer get validated even with `shouldUnregister: false`
322
+
323
+ ## [7.4.0] - 2021-05-04
324
+
325
+ ### Added
326
+
327
+ - new `name` prop for `useFormState` to subscribe to individual inputs.
328
+
329
+ ```ts
330
+ useFormState({
331
+ name: 'inputName', // optional and can be array of inputs' name as well
332
+ });
333
+ ```
334
+
335
+ ## [7.2.2] - 2021-04-21
336
+
337
+ ### Changes
338
+
339
+ - set `shouldUnregister` to `true` will not shallow merge `defaultValues`
340
+
341
+ ## [7.2.0] - 2021-04-19
342
+
343
+ ### Changes
344
+
345
+ - `shouldUnregister` config to remove input value after unmount
346
+
347
+ ```tsx
348
+ // Global config (can't be overwrite)
349
+ useForm({
350
+ shouldUnregister: true // default to false
351
+ })
352
+
353
+ // Component/Hook level config (can not overwrites global config)
354
+ register('test', {
355
+ shouldUnregister: true // default to false
356
+ })
357
+
358
+ <Controller shouldUnregister={true} />
359
+
360
+ useController({ shouldUnregister: true })
361
+
362
+ useFieldArray({ shouldUnregister: true })
363
+ ```
364
+
365
+ ## [7.0.6] - 2021-04-12
366
+
367
+ ### Changes
368
+
369
+ - `register` will retrieve `onChange`'s target value when component'ref is not a valid input element.
370
+
371
+ ## [7.0.0-rc.7] - 2021-03-28
372
+
373
+ ### Changes
374
+
375
+ - change type name from `RefCallbackHandler` to `UseFormRegisterReturn` for register callback's return
376
+
377
+ ## [7.0.0-rc.7] - 2021-03-23
378
+
379
+ ### Changes
380
+
381
+ - `useFieldArray` will produce an empty array `[]` when no field is presented.
382
+
383
+ ## [7.0.0-rc.1] - 2021-03-08
384
+
385
+ ### Changes
386
+
387
+ - `setValue` with field array will `register` all inputs before rendering.
388
+
389
+ ## [7.0.0-beta.17] - 2021-03-03
390
+
391
+ ### Changes
392
+
393
+ - `append`, `prepend` and `insert` will `register` deeply nested inputs at `useFieldArray`.
394
+
395
+ ## [7.0.0-beta.15] - 2021-02-27
396
+
397
+ ### Changes
398
+
399
+ - typescript array index restriction removed.
400
+ - `append`, `prepend` and `insert` will `register` inputs during each action at `useFieldArray`.
401
+
402
+ ## [7.0.0-beta.11] - 2021-02-20
403
+
404
+ ### Changes
405
+
406
+ - change `ArrayKey` type to `number | '${number}'`
407
+
408
+ ## [7.0.0-beta.10] - 2021-02-19
409
+
410
+ ### Changes
411
+
412
+ - Change `useController`'s `meta` into `fieldState` and include `formState`, these change will be applied to `Controller` too.
413
+
414
+ ```diff
415
+ - const { field, meta } = useController({ control });
416
+ + const { field, fieldState, formState } = useController({ control });
417
+ ```
418
+
419
+ ## [7.0.0-beta.9] - 2021-02-19
420
+
421
+ ### Changes
422
+
423
+ - typescript array index support is changed to `49` instead of `99`
424
+
425
+ ## [7.0.0-beta.4] - 2021-02-08
426
+
427
+ - **Breaking change:** `valueAs` will be run before the built-in validation and `resolver`
428
+
429
+ ```diff
430
+ - <input {...register('test', { validate: (data: string) => {}, valueAsNumber: true })} />
431
+ + <input {...register('test', { validate: (data: number) => {}, valueAsNumber: true })} />
432
+ ```
433
+
434
+ ## [7.0.0-beta.1] - 2021-02-08
435
+
436
+ ### Changes
437
+
438
+ - `useWatch` will no longer required `defaultValue` for field Array
439
+
440
+ ## [7.0.0-beta.0] - 2021-02-06
441
+
442
+ ### Changes
443
+
444
+ - **Breaking change:** shallow merge defaultValues with result (#4074)
445
+
446
+ ```ts
447
+ useForm({ defaultValues: { test: 'test' } });
448
+
449
+ getValues(); // v6 will return {}
450
+ getValues(); // v7 will return { test: 'test' }
451
+ ```
452
+
453
+ ## [v7.0.0-alpha.2] - 2021-02-04
454
+
455
+ ### Changes
456
+
457
+ - **Breaking change:** `setError`'s `shouldFocus` option has been moved into the third argument.
458
+
459
+ ```diff
460
+ - setError('test', { type: 'type', message: 'issue', shouldFocus: true })
461
+ + setError('test', { type: 'type', message: 'issue' }, { shouldFocus: true })
462
+ ```
463
+
464
+ - **Breaking change:** type name changes:
465
+
466
+ ```diff
467
+ - UseFormMethods
468
+ + UseFormReturn
469
+ - UseFormOptions
470
+ + UseFormProps
471
+ - UseFieldArrayMethods
472
+ + UseFieldArrayReturn
473
+ - UseFieldArrayOptions
474
+ + UseFieldArrayProps
475
+ - UseControllerMethods
476
+ + UseControllerReturn
477
+ - UseControllerOptions
478
+ + UseControllerProps
479
+ - ArrayField
480
+ + FieldArray
481
+ ```
482
+
483
+ ### Fixes
484
+
485
+ - fix `setValue` with `Controller` and `reset` with `useFieldArray` issues: 4111 & 4108 (#4113)
486
+
487
+ ## [v7.0.0-alpha.2] - 2021-02-02
488
+
489
+ ### Changes
490
+
491
+ - **Breaking change:** `setError`'s `shouldFocus` option has been moved to the third argument.
492
+
493
+ ```diff
494
+ - setError('test', { type: 'type', message: 'issue', shouldFocus: true })
495
+ + setError('test', { type: 'type', message: 'issue' }, { shouldFocus: true })
496
+ ```
497
+
498
+ ### Fixes
499
+
500
+ - fix #4078 issue with watch + mode: onChange
501
+
502
+ ### Improvements
503
+
504
+ - remove internal deep clone (#4088)
505
+ - remove transformToNestObject (#4089)
506
+
507
+ ## [v7.0.0-alpha.1] - 2021-02-01
508
+
509
+ ### Changes
510
+
511
+ - field name reference will be removed with `unregister` (#4010)
512
+
513
+ - **Breaking change:** improve field array remove result and no longer remove field array value after unmount
514
+
515
+ ```diff
516
+ const { remove } = useFieldArray({ name: 'test' })
517
+ remove();
518
+ getValues(); // V6: result form value {}
519
+ getValues(); // V7: result form value { test: [] }
520
+ ```
521
+
522
+ ### Improvements
523
+
524
+ - change internal field names into `Set` (#4015)
525
+ - improve `onChange` perf with `resolver (#4017)
526
+ - improve field array name look up perf (#4030)
527
+
528
+ ## [v7.0.0-alpha.0] - 2021-01-31
529
+
530
+ ### Added
531
+
532
+ - new custom hook `useFormState` (#3740)
533
+
534
+ ```ts
535
+ const { isDirty, errors } = useFormState();
536
+ ```
537
+
538
+ - `watch` support can subscribe to the entire form with a callback
539
+
540
+ ```ts
541
+ watch((data, { name, type }) => {
542
+ console.log('formValue', data);
543
+ console.log('name', name);
544
+ console.log('type', type);
545
+ });
546
+ ```
547
+
548
+ - `useController` includes new `isValidating` state (#3778)
549
+ - `useController` includes new `error` state (#3921)
550
+
551
+ ```ts
552
+ const {
553
+ meta: { error, isValidating },
554
+ } = useController({ name: 'test' });
555
+ ```
556
+
557
+ - new `unregister` second argument (#3964)
558
+
559
+ ```ts
560
+ unregister('test', { keepDirty: true });
561
+ ```
562
+
563
+ - Resolver add `field` being validated (#3881)
564
+
565
+ ```diff
566
+ - resolver: (values: any, context?: object) => Promise<ResolverResult> | ResolverResult
567
+ + resolver: (
568
+ + values: any,
569
+ + context?: object,
570
+ + options: {
571
+ + criteriaMode?: 'firstError' | 'all',
572
+ + names?: string[],
573
+ + fields: { [name]: field } // Support nested field
574
+ + }
575
+ + ) => Promise<ResolverResult> | ResolverResult
576
+ ```
577
+
578
+ - `useFieldArray` action can focus input by name and index
579
+
580
+ ```ts
581
+ append(object, config: { shouldDirty: boolean, focusIndex: number, focusName: string })
582
+ insert(object, config: { shouldDirty: boolean, focusIndex: number, focusName: string })
583
+ prepend(object, config: { shouldDirty: boolean, focusIndex: number, focusName: string })
584
+ ```
585
+
586
+ ### Changes
587
+
588
+ - **Breaking change:** No longer support IE 11 support
589
+
590
+ - **Breaking change:** `register` has been changed from register at `ref` to a function which needs to be spread as props.
591
+
592
+ ```diff
593
+ - <input ref={register, { required: true }} name="test" />
594
+ + <input {...register('name', { required: true })} />
595
+ + <TextInput {...register('name', { required: true })} />
596
+ ```
597
+
598
+ - **Breaking change:** `name` with array will only support dot syntax instead of brackets.
599
+
600
+ ```
601
+ - test[2].test
602
+ + test.2.test
603
+ ```
604
+
605
+ - **Breaking change:** remove `as` prop at `Controller` and fix render prop consistency (#3732)
606
+
607
+ ```diff
608
+ - <Controller render={props => <input {...props} />} />
609
+ + <Controller render={({ field }) => <input {...field} />} />
610
+ ```
611
+
612
+ - **Breaking change:** remove `errors` alias (#3737)
613
+
614
+ ```diff
615
+ - const { errors } = useForm();
616
+ + const { formState: { errors } } = useForm();
617
+ ```
618
+
619
+ - **Breaking change:** improved `reset` second argument (#3905)
620
+
621
+ ```diff
622
+ - reset({}, { isDirty: true })
623
+ + reset({}, { keepIsDirty: true })
624
+ ```
625
+
626
+ - **Breaking change:** change `touched` to `touchedFields` for consistency (#3923)
627
+
628
+ ```diff
629
+ - const { formState: { touched } } = useForm();
630
+ + const { formState: { touchedFields }} = useForm();
631
+ ```
632
+
633
+ - **Breaking change:** `trigger` will no longer return validation result.
634
+
635
+ ```diff
636
+ - await trigger('test') // return true or false
637
+ + trigger('test') // void
638
+ ```
639
+
640
+ - remove `isSubmitting` proxy (#4000)
641
+
642
+ - input `register` will no longer be removed due to unmount, user will have to manually invoke `unregister`
643
+
644
+ ### Improvements
645
+
646
+ - `useWatch` internal mechanism improvement (#3754)
647
+ - `Controller` and `useController` apply `useFormState` internally and improve performance (#3778)
648
+ - `register` type support for input name (#3738)
649
+ - `Controller` and `useCOntroller` type support for input name (#3738)
650
+ - `useFieldArray` internal logic and data structure improvement (#3858)
651
+ - improve `useFieldArray` internal fields update with subscription (#3943)
652
+ - improve tests structure (#3916)
653
+ - `useWatch` type improvement (#3931)
654
+ - improve type support for nested field array with `const` (#3920)
655
+ - improve `useFieldArray` internal type structure (#3986)
656
+ - `MutationObserver` removed from `useForm`
657
+
658
+ ## [6.15.0] - 2021-02-02
659
+
660
+ ### Changed
661
+
662
+ - radio input default selection will return `null` instead of empty string `''`
663
+ - `valueAsNumber` with empty input will return `NaN` instead of `0`
664
+
665
+ ## [6.14.0] - 2020-12-31
666
+
667
+ ### Changed
668
+
669
+ - `setValue` without shouldUnregister:false will no longer deep clone its value instead with shallow clone
670
+
671
+ ### Added
672
+
673
+ - new formState `isValidating`, this will set to `true` during validation.
674
+
675
+ ```ts
676
+ const {
677
+ formState: { isValidating },
678
+ } = useForm();
679
+ ```
680
+
681
+ ## [6.12.0] - 2020-12-12
682
+
683
+ ### Changed
684
+
685
+ - When invoking `reset({ value })` value will be shallow clone value object which you have supplied instead of deepClone.
686
+
687
+ ```tsx
688
+ // ❌ avoid the following with deep nested default values
689
+ const defaultValues = { object: { deepNest: { file: new File() } } };
690
+ useForm({ defaultValues });
691
+ reset(defaultValues); // share the same reference
692
+
693
+ // ✅ it's safer with the following, as we only doing shallow clone with defaultValues
694
+ useForm({ deepNest: { file: new File() } });
695
+ reset({ deepNest: { file: new File() } });
696
+ ```
697
+
698
+ ### Added
699
+
700
+ - New custom hook `useController`: This custom hook is what powers Controller, and shares the same props and methods as Controller. It's useful to create reusable Controlled input, while Controller is the flexible option to drop into your page or form.
701
+
702
+ ```tsx
703
+ import React from 'react';
704
+ import { TextField } from '@material-ui/core';
705
+ import { useController } from 'react-hook-form';
706
+
707
+ function Input({ control, name }) {
708
+ const {
709
+ field: { ref, ...inputProps },
710
+ meta: { invalid, isTouched, isDirty },
711
+ } = useController({
712
+ name,
713
+ control,
714
+ rules: { required: true },
715
+ defaultValue: '',
716
+ });
717
+
718
+ return <TextField {...inputProps} inputRef={ref} />;
719
+ }
720
+ ```
721
+
722
+ ## [6.12.0] - 2020-11-28
723
+
724
+ ### Changed
725
+
726
+ - `useWatch` will retrieve the latest value from `reset(data)` instead of return `defaultValue`
727
+
728
+ ```tsx
729
+ useWatch({
730
+ name: 'test',
731
+ defaultValue: 'data', // this value will only show on the initial render
732
+ });
733
+ ```
734
+
735
+ - TS: name changed from `ValidationRules` to `RegisterOptions` due to valueAs functionality included as `register` function.
736
+
737
+ ### Added
738
+
739
+ - `register` function with additional options to transform value
740
+
741
+ - `valueAsDate`
742
+ - `valueAsNumber`
743
+ - `setValue`
744
+
745
+ ```tsx
746
+ register({
747
+ valueAsNumber: true,
748
+ });
749
+
750
+ register({
751
+ valueAsNumber: true,
752
+ });
753
+
754
+ register({
755
+ setValueAs: (value) => value,
756
+ });
757
+ ```
758
+
759
+ ### Added
760
+
761
+ ## [6.11.0] - 2020-11-07
762
+
763
+ ### Changed
764
+
765
+ - `defaultValues` is **required** to measure `isDirty`, keep a single source of truth to avoid multiple issues raised around `isDirty`
766
+ - when `watch` with `useFieldArray`, `fields` object is no longer required as defaultValue
767
+
768
+ ```diff
769
+ - watch('fieldArray', fields);
770
+ + watch('fieldArray');
771
+ ```
772
+
773
+ ## [6.10.0] - 2020-10-31
774
+
775
+ ### Added
776
+
777
+ - `Controller` will have an extra `ref` props to improve DX in terms of focus management.
778
+
779
+ ```tsx
780
+ <Controller
781
+ name="test"
782
+ render={(props) => {
783
+ return (
784
+ <input
785
+ value={props.value}
786
+ onChange={props.onChange}
787
+ ref={props.ref} // you can assign ref now without the use of `onFocus`
788
+ />
789
+ );
790
+ }}
791
+ />
792
+
793
+ // focus will work correct without the `onFocus` prop
794
+ <Controller name="test" as={<input />} />
795
+ ```
796
+
797
+ ### Changed
798
+
799
+ - `resolver` with group error object will no longer need with `trigger` to show and clear error. This minor version made hook form look at parent error node to detect if there is any group error to show and hide.
800
+
801
+ ```tsx
802
+ const schema = z.object({
803
+ items: z.array(z.boolean()).refine((items) => items.some((item) => item)),
804
+ });
805
+
806
+ {
807
+ items.map((flag, index) => (
808
+ <input
809
+ type="checkbox"
810
+ defaultChecked={false}
811
+ // onChange={() => trigger("items")} now can be removed
812
+ ref={register}
813
+ name={`items.${index}`}
814
+ />
815
+ ));
816
+ }
817
+ ```
818
+
819
+ ## [6.9.0] - 2020-10-3
820
+
821
+ ### Changed
822
+
823
+ - with shouldUnregister set to false, empty Field Array will default [] as submission result.
824
+
825
+ ```tsx
826
+ const { handleSubmit } = useForm({
827
+ shouldUnregister: false,
828
+ });
829
+
830
+ useFieldArray({
831
+ name: 'test',
832
+ });
833
+
834
+ handleSubmit((data) => {
835
+ // shouldUnregister: false
836
+ // result: { data: {test: []} }
837
+ // shouldUnregister: true
838
+ // result: {}
839
+ });
840
+ ```
841
+
842
+ ## [6.8.4] - 2020-09-22
843
+
844
+ ### Changed
845
+
846
+ - when input unmounts `touched` and `dirtyFields` will no longer get removed from `formState` (shouldUnregister: true).
847
+
848
+ ## [6.8.0] - 2020-09-09
849
+
850
+ ### Added
851
+
852
+ - new formState `isSubmitSuccessful` to indicate successful submission
853
+ - `setError` now support focus on the actual input
854
+
855
+ ```typescript jsx
856
+ setError('test', { message: 'This is required', shouldFocus: true });
857
+ ```
858
+
859
+ ### Changed
860
+
861
+ - with `shouldUnregister:false` `defaultValues` data will be part of the submission data
862
+ - with `shouldUnregister:false` conditional field is going to work with `useFieldArray`
863
+ - `setValue` now support `useFieldArray`
864
+
865
+ ```diff
866
+ - setValue('test', 'data')
867
+ + setValue('test', [{ test: '123' }]) // make it work for useFieldArray and target a field array key
868
+ ```
869
+
870
+ - remove `exact` config at clearErrors
871
+
872
+ ```diff
873
+ - clearErrors('test', { exact: false })
874
+ + clearErrors('test') // does it automatically in the lib
875
+ ```
876
+
877
+ ## [6.7.0] - 2020-08-30
878
+
879
+ ### Added
880
+
881
+ - `clearError` have second option argument for clear errors which are exact or key name
882
+
883
+ ```ts
884
+ register('test.firstName', { required: true });
885
+ register('test.lastName', { required: true });
886
+ clearErrors('test', { exact: false }); // will clear both errors from test.firstName and test.lastName
887
+ clearErrors('test.firstName'); // for clear single input error
888
+ ```
889
+
890
+ ## [6.6.0] - 2020-08-28
891
+
892
+ ### Changed
893
+
894
+ - all types from this lib has been exported. **Important:** only documented type: https://react-hook-form.com/ts will avoid breaking change.
895
+
896
+ ## [6.5.0] - 2020-08-23
897
+
898
+ ### Changed
899
+
900
+ - `errors` is also part of `formState` object
901
+ - `disabled` input will not be part of the submission data by following the [HTML standard](https://html.spec.whatwg.org/multipage/forms.html#constructing-the-form-data-set)
902
+
903
+ ## [6.4.0] - 2020-08-15
904
+
905
+ ### Added
906
+
907
+ - `Controller`'s `render` prop will pass down `name` prop
908
+ - `handleSubmit` take a second callback for errors callback
909
+ - new mode `onTouched` will only trigger validation after inputs are touched
910
+
911
+ ### Changed
912
+
913
+ - `register` no longer compare `ref` difference with React Native
914
+
915
+ ## [6.3.2] - 2020-08-11
916
+
917
+ ### Changed
918
+
919
+ - IE 11 version will be required to install `@babel/runtime-corejs3` as dependency at your own project
920
+
921
+ ## [6.3.0] - 2020-08-8
922
+
923
+ ### Changed
924
+
925
+ - `defaultValue` is become **required** for `useFieldArray` at each input
926
+
927
+ ## [6.2.0] - 2020-07-30
928
+
929
+ ### Changed
930
+
931
+ - revert `getValues` will return default values before inputs registration
932
+
933
+ ## [6.1.0] - 2020-07-26
934
+
935
+ ### Changed
936
+
937
+ - `resolver` supports both async and sync
938
+ - `getValues` will return default values before inputs registration
939
+
940
+ ## [6.0.7] - 2020-07-17
941
+
942
+ ### Added
943
+
944
+ - export `ArrayField` type
945
+
946
+ ### Changed
947
+
948
+ - error message will support array of messages for specific type
949
+
950
+ ```diff
951
+ - export type ValidateResult = Message | boolean | undefined;
952
+ + export type ValidateResult = Message | Message[] | boolean | undefined;
953
+ ```
954
+
955
+ ## [6.0.3] - 2020-07-10
956
+
957
+ ### Changed
958
+
959
+ - Controller `onFocus` works with React Native
960
+ - Controller stop producing `checked` prop by boolean `value`
961
+
962
+ ## [6.0.2] - 2020-07-8
963
+
964
+ ### Added
965
+
966
+ - export `UseFormOptions`, `UseFieldArrayOptions`, `FieldError`, `Field` and `Mode` type
967
+
968
+ ## [6.0.1] - 2020-07-3
969
+
970
+ ### Added
971
+
972
+ - export `ValidationRules` type
973
+
974
+ ## [6.0.0] - 2020-07-1
975
+
976
+ ### Added
977
+
978
+ - config for `shouldUnregister` which allow input to be persist even after unmount
979
+
980
+ ```typescript
981
+ useForm({
982
+ shouldUnregister: false, // unmount input state will be remained
983
+ });
984
+ ```
985
+
986
+ - auto focus with useFieldArray
987
+
988
+ ```ts
989
+ append({}, (autoFocus = true));
990
+ prepend({}, (autoFocus = true));
991
+ insert({}, (autoFocus = true));
992
+ ```
993
+
994
+ - TS: NestedValue
995
+
996
+ ```tsx
997
+ import { useForm, NestedValue } from 'react-hook-form';
998
+
999
+ type FormValues = {
1000
+ key1: string;
1001
+ key2: number;
1002
+ key3: NestedValue<{
1003
+ key1: string;
1004
+ key2: number;
1005
+ }>;
1006
+ key4: NestedValue<string[]>;
1007
+ };
1008
+
1009
+ const { errors } = useForm<FormValues>();
1010
+
1011
+ errors?.key1?.message; // no type error
1012
+ errors?.key2?.message; // no type error
1013
+ errors?.key3?.message; // no type error
1014
+ errors?.key4?.message; // no type error
1015
+ ```
1016
+
1017
+ - `useWatch` (new) subscribe to registered inputs.
1018
+
1019
+ ```tsx
1020
+ <input name="test" ref={register} />;
1021
+
1022
+ function IsolateReRender() {
1023
+ const { state } = useWatch({
1024
+ name: 'test',
1025
+ control,
1026
+ defaultValue: 'default',
1027
+ });
1028
+
1029
+ return <div>{state}</div>;
1030
+ }
1031
+ ```
1032
+
1033
+ - `getValues()` support array of field names
1034
+
1035
+ ```typescript jsx
1036
+ getValues(['test', 'test1']); // { test: 'test', test1: 'test1' }
1037
+ ```
1038
+
1039
+ - `useForm({ mode: 'all' })` support all validation
1040
+
1041
+ ### Changed
1042
+
1043
+ - rename `validationResolver` to `resolver`
1044
+ - rename `validationContext` to `context`
1045
+ - rename `validateCriteriaMode` to `criteriaMode`
1046
+ - rename `triggerValidation` to `trigger`
1047
+ - rename `clearError` to `clearErrors`
1048
+ - rename `FormContext` to `FormProvider`
1049
+ - rename `dirty` to `isDirty`
1050
+ - `dirtyFields` change type from `Set` to `Object`
1051
+
1052
+ - Controller with render props API, and removed the following props:
1053
+ - onChange
1054
+ - onChangeName
1055
+ - onBlur
1056
+ - onBlurName
1057
+ - valueName
1058
+
1059
+ ```diff
1060
+ -<Controller
1061
+ - as={CustomInput}
1062
+ - valueName="textValue"
1063
+ - onChangeName="onTextChange"
1064
+ - control={control}
1065
+ - name="test"
1066
+ -/>
1067
+ +<Controller
1068
+ + render={({ onChange, onBlur, value }) => (
1069
+ + <CustomInput onTextChange={onChange} onBlur={onBlur} textValue={value} />
1070
+ + )}
1071
+ + control={control}
1072
+ + name="test"
1073
+ +/>
1074
+ ```
1075
+
1076
+ - `setError` will focus one error at a time and remove confusing set multiple errors, behavior change.
1077
+ - setError will persis an error if it's not part of the form, which requires manual remove with clearError
1078
+ - setError error will be removed by validation rules, rules always take over errors
1079
+
1080
+ ```diff
1081
+ - setError('test', 'test', 'test')
1082
+ + setError('test', { type: 'test', message: 'bill'})
1083
+ ```
1084
+
1085
+ - `setValue` will focus on input at a time
1086
+
1087
+ ```diff
1088
+ setValue('test', 'value', { shouldValidate: false, shouldDirty: false })
1089
+ ```
1090
+
1091
+ ### Removed
1092
+
1093
+ - remove `validationSchema` and embrace validation `resolver`
1094
+ - remove `nest` option for `watch` & `getValues`, so data return from both methods will be in FormValues shape.
1095
+
1096
+ ```diff
1097
+ -getValues({ nest: true }); // { test: { data: 'test' }}
1098
+ -watch({ nest: true }); // { test: { data: 'test' }}
1099
+ +getValues(); // { test: { data: 'test' }}
1100
+ +watch(); // { test: { data: 'test' }}
1101
+ ```
1102
+
1103
+ ## [5.0.0] - 2020-03-07
1104
+
1105
+ ### Breaking Change
1106
+
1107
+ - `Controller`: onChange will only evaluate payload as event like object. eg: react-select will no longer need the extra `onChange` method at `Controller`.
1108
+
1109
+ ```diff
1110
+ import { TextInput } from 'react-native';
1111
+
1112
+ -<Controller
1113
+ - as={<TextInput style={{ borderWidth: 2, borderColor: 'black'}} />}
1114
+ - name="text"
1115
+ - control={args => ({
1116
+ - value: args[0].nativeEvent.text,
1117
+ - })}
1118
+ - onChange={onChange}
1119
+ -/>
1120
+ +<Controller
1121
+ + as={<TextInput style={{ borderWidth: 2, borderColor: 'black'}} />}
1122
+ + name="text"
1123
+ + control={args => args[0].nativeEvent.text}
1124
+ + onChange={onChange}
1125
+ +/>
1126
+ ```
1127
+
1128
+ ## [4.0.0] - 2019-12-24
1129
+
1130
+ ### Breaking changes
1131
+
1132
+ - improve module **exports**:
1133
+
1134
+ ```tsx
1135
+ import { useForm } from 'react-hook-form';
1136
+ ```
1137
+
1138
+ - nested `errors` object and better typescript support
1139
+
1140
+ ```tsx
1141
+ type form = {
1142
+ yourDetail: {
1143
+ firstName: string;
1144
+ };
1145
+ };
1146
+
1147
+ errors?.yourDetail?.firstName;
1148
+ ```
1149
+
1150
+ - triggerValidation argument change from `Object`, `Object[]` to `String`, `String[]`
1151
+
1152
+ ```tsx
1153
+ triggerValidation('firstName');
1154
+ triggerValidation(['firstName', 'lastName']);
1155
+ ```
1156
+
1157
+ - watch support `{ nest: boolean }`
1158
+
1159
+ ```tsx
1160
+ watch(); // { 'test.firstName': 'bill' }
1161
+ watch({ nest: true }); // { test: { firstName: 'bill' } }
1162
+ ```
1163
+
1164
+ - improve custom `register`
1165
+
1166
+ ```tsx
1167
+ register('test', { required: true });
1168
+ ```
1169
+
1170
+ - setError` support nested object
1171
+
1172
+ ```tsx
1173
+ setError('yourDetail.firstName', 'test');
1174
+ errors.yourDetails.firstName;
1175
+ ```
1176
+
1177
+ - `handleSubmit` no longer rerun array inputs contains `undefined` or `null`
1178
+
1179
+ ### Added
1180
+
1181
+ - move `RHFInput` into the main repo and rename it to `Controller`
1182
+
1183
+ ```tsx
1184
+ <Controller control={control} name="test" />
1185
+ ```
1186
+
1187
+ ### Removed
1188
+
1189
+ - `validationSchemaOption`: hardly anyone want to use validation with abort early, or change the config.
1190
+
1191
+ - native validation: hardly anyone used this feature. https://react-hook-form.com/api/#Browserbuiltinvalidation
1192
+
1193
+ ## [3.0.0] - 2019-04-21
1194
+
1195
+ ### Added
1196
+
1197
+ React Hook Form return a new `formState: Object` which contain the following information
1198
+
1199
+ - `dirty`: when user interactive any fields
1200
+ - `touched`: what are the fields have interacted
1201
+ - `isSubmitted`: whether the form have been triggered with submitting
1202
+
1203
+ ```tsx
1204
+ const {
1205
+ formState: { dirty, touched, isSubmitted },
1206
+ } = useForm();
1207
+ ```
1208
+
1209
+ ## [2.0.0] - 2019-03-29
1210
+
1211
+ ### Added
1212
+
1213
+ - support `ref={register}` instead of only `ref={register()}`