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