@rolster/react-forms 19.4.3 → 19.4.7
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/dist/cjs/index.cjs +159 -95
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/form-array/form-array-control.type.d.ts +2 -0
- package/dist/esm/form-array/form-array-group.d.ts +1 -0
- package/dist/esm/form-array/form-array-group.helper.js +1 -1
- package/dist/esm/form-array/form-array-group.helper.js.map +1 -1
- package/dist/esm/form-array/form-array-group.js +5 -0
- package/dist/esm/form-array/form-array-group.js.map +1 -1
- package/dist/esm/form-array/form-array-group.type.d.ts +1 -0
- package/dist/esm/form-array/form-array-list.d.ts +2 -1
- package/dist/esm/form-array/form-array-list.js +37 -6
- package/dist/esm/form-array/form-array-list.js.map +1 -1
- package/dist/esm/form-array/form-array-list.type.d.ts +5 -0
- package/dist/esm/form-array/form-array.js +29 -17
- package/dist/esm/form-array/form-array.js.map +1 -1
- package/dist/esm/form-control/form-control.type.d.ts +2 -0
- package/dist/esm/form-group/form-group.js +65 -64
- package/dist/esm/form-group/form-group.js.map +1 -1
- package/dist/esm/form-ref/form-ref.js +23 -8
- package/dist/esm/form-ref/form-ref.js.map +1 -1
- package/package.json +3 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -133,7 +133,7 @@ function replaceControl(controls, control) {
|
|
|
133
133
|
controls[key] = control;
|
|
134
134
|
}
|
|
135
135
|
return controls;
|
|
136
|
-
}, controls);
|
|
136
|
+
}, { ...controls });
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
function refactorForValid$2(controls, validators) {
|
|
@@ -217,6 +217,11 @@ class RolsterArrayGroup {
|
|
|
217
217
|
setResource(resource) {
|
|
218
218
|
this.refresh('resource', { resource });
|
|
219
219
|
}
|
|
220
|
+
reset() {
|
|
221
|
+
Object.values(this.controls).forEach((control) => {
|
|
222
|
+
control.reset();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
220
225
|
refresh(action, options) {
|
|
221
226
|
this.subscriber &&
|
|
222
227
|
this.subscriber(action, new RolsterArrayGroup({ ...this, ...options }));
|
|
@@ -251,12 +256,14 @@ function formArrayGroup(options, validators) {
|
|
|
251
256
|
|
|
252
257
|
class RolsterArrayList extends RolsterArrayControl {
|
|
253
258
|
constructor(options) {
|
|
254
|
-
const { controls, valueToControls, validators } = options;
|
|
259
|
+
const { controls, controlsUuid, valueToControls, valueToUuid, validators } = options;
|
|
255
260
|
const value = controls.map(helpers.controlsToValue);
|
|
256
261
|
const errors = validators ? helpers.formControlIsValid({ value, validators }) : [];
|
|
257
262
|
super({ ...options, errors, value });
|
|
258
263
|
this.valueToControls = valueToControls;
|
|
264
|
+
this.valueToUuid = valueToUuid;
|
|
259
265
|
this.controls = controls;
|
|
266
|
+
this.controlsUuid = controlsUuid ?? controls.map(() => uuid.v4());
|
|
260
267
|
this.valid =
|
|
261
268
|
errors.length === 0 &&
|
|
262
269
|
controls.reduce((valid, controls) => valid && helpers.verifyAllTrueInControls(controls, 'valid'), true);
|
|
@@ -267,49 +274,76 @@ class RolsterArrayList extends RolsterArrayControl {
|
|
|
267
274
|
});
|
|
268
275
|
}
|
|
269
276
|
setDefaultValue(value) {
|
|
277
|
+
console.log(value);
|
|
278
|
+
console.log(this.generateControlsUuid(value));
|
|
270
279
|
this.refresh('list', {
|
|
271
280
|
controls: value.map(this.valueToControls),
|
|
281
|
+
controlsUuid: this.generateControlsUuid(value),
|
|
272
282
|
defaultValue: value
|
|
273
283
|
});
|
|
274
284
|
}
|
|
275
285
|
setStartValue(value) {
|
|
276
286
|
this.refresh('list', {
|
|
277
|
-
controls: value.map(this.valueToControls)
|
|
287
|
+
controls: value.map(this.valueToControls),
|
|
288
|
+
controlsUuid: this.generateControlsUuid(value)
|
|
278
289
|
});
|
|
279
290
|
}
|
|
280
291
|
setValue(value) {
|
|
292
|
+
console.log(value);
|
|
293
|
+
console.log(this.generateControlsUuid(value));
|
|
281
294
|
this.refresh('list', {
|
|
282
295
|
controls: value.map(this.valueToControls),
|
|
296
|
+
controlsUuid: this.generateControlsUuid(value),
|
|
283
297
|
dirty: true
|
|
284
298
|
});
|
|
285
299
|
}
|
|
286
300
|
reset() {
|
|
287
301
|
this.refresh('list', {
|
|
288
302
|
controls: this.defaultValue.map(this.valueToControls),
|
|
303
|
+
controlsUuid: this.generateControlsUuid(this.defaultValue),
|
|
289
304
|
dirty: false,
|
|
290
305
|
touched: false
|
|
291
306
|
});
|
|
292
307
|
}
|
|
293
308
|
push(controls) {
|
|
309
|
+
const _uuid = this.valueToUuid?.(helpers.controlsToValue(controls)) ?? uuid.v4();
|
|
294
310
|
this.refresh('list', {
|
|
295
|
-
controls: [...this.controls, controls]
|
|
311
|
+
controls: [...this.controls, controls],
|
|
312
|
+
controlsUuid: [...this.controlsUuid, _uuid]
|
|
296
313
|
});
|
|
297
314
|
}
|
|
298
315
|
remove(controls) {
|
|
316
|
+
const _controls = [];
|
|
317
|
+
const _controlsUuid = [];
|
|
318
|
+
this.controls.forEach((currentControls, index) => {
|
|
319
|
+
if (currentControls !== controls) {
|
|
320
|
+
_controls.push(currentControls);
|
|
321
|
+
_controlsUuid.push(this.controlsUuid[index]);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
299
324
|
this.refresh('list', {
|
|
300
|
-
controls:
|
|
325
|
+
controls: _controls,
|
|
326
|
+
controlsUuid: _controlsUuid
|
|
301
327
|
});
|
|
302
328
|
}
|
|
329
|
+
findControlsByUuid(uuid) {
|
|
330
|
+
const index = this.controlsUuid.indexOf(uuid);
|
|
331
|
+
return index >= 0 ? this.controls[index] : undefined;
|
|
332
|
+
}
|
|
303
333
|
builder(options) {
|
|
304
334
|
return new RolsterArrayList({
|
|
305
335
|
...this,
|
|
306
336
|
...options,
|
|
307
|
-
valueToControls: this.valueToControls
|
|
337
|
+
valueToControls: this.valueToControls,
|
|
338
|
+
valueToUuid: this.valueToUuid
|
|
308
339
|
});
|
|
309
340
|
}
|
|
310
341
|
refresh(action, options) {
|
|
311
342
|
super.refresh(action, options);
|
|
312
343
|
}
|
|
344
|
+
generateControlsUuid(values) {
|
|
345
|
+
return values.map((value) => this.valueToUuid?.(value) ?? uuid.v4());
|
|
346
|
+
}
|
|
313
347
|
_subscribe(reactControls) {
|
|
314
348
|
Object.values(reactControls).forEach((control) => {
|
|
315
349
|
control.subscribe((action, _control) => {
|
|
@@ -322,10 +356,12 @@ class RolsterArrayList extends RolsterArrayControl {
|
|
|
322
356
|
}
|
|
323
357
|
}
|
|
324
358
|
function formArrayList(options) {
|
|
359
|
+
const { valueToControls, valueToUuid } = options;
|
|
325
360
|
const value = options?.value || [];
|
|
326
361
|
return new RolsterArrayList({
|
|
327
362
|
...options,
|
|
328
|
-
controls: value.map(
|
|
363
|
+
controls: value.map(valueToControls),
|
|
364
|
+
controlsUuid: value.map((v) => valueToUuid?.(v) ?? uuid.v4()),
|
|
329
365
|
defaultValue: value,
|
|
330
366
|
uuid: uuid.v4()
|
|
331
367
|
});
|
|
@@ -360,29 +396,22 @@ function refactorForControls(action, state, groups) {
|
|
|
360
396
|
}
|
|
361
397
|
function useFormArray(options, validators) {
|
|
362
398
|
const formArray = helpers.createFormArrayOptions(options, validators);
|
|
363
|
-
const
|
|
364
|
-
const
|
|
399
|
+
const refArrayValue = react.useRef(formArray.groups || []);
|
|
400
|
+
const refArrayGroups = react.useRef(new Map());
|
|
365
401
|
const [state, setState] = react.useState(() => {
|
|
366
402
|
return {
|
|
367
|
-
...refactorForValid$1(
|
|
368
|
-
controls:
|
|
403
|
+
...refactorForValid$1(refArrayValue.current, formArray.validators),
|
|
404
|
+
controls: refArrayValue.current.map(({ controls }) => controls),
|
|
369
405
|
dirty: false,
|
|
370
406
|
dirties: false,
|
|
371
407
|
disabled: false,
|
|
372
|
-
groups:
|
|
408
|
+
groups: refArrayValue.current,
|
|
373
409
|
touched: false,
|
|
374
410
|
toucheds: false,
|
|
375
|
-
value:
|
|
411
|
+
value: refArrayValue.current.map(({ controls }) => helpers.controlsToValue(controls)),
|
|
376
412
|
validators: formArray.validators
|
|
377
413
|
};
|
|
378
414
|
});
|
|
379
|
-
react.useEffect(() => {
|
|
380
|
-
formGroups.current.clear();
|
|
381
|
-
state.groups.forEach((group) => {
|
|
382
|
-
formGroups.current.set(group.uuid, group);
|
|
383
|
-
group.subscribe(subscriber);
|
|
384
|
-
});
|
|
385
|
-
}, [state.groups]);
|
|
386
415
|
const subscriber = react.useCallback((action, group) => {
|
|
387
416
|
setState((state) => {
|
|
388
417
|
const groups = state.groups.map((currentGroup) => {
|
|
@@ -394,6 +423,17 @@ function useFormArray(options, validators) {
|
|
|
394
423
|
};
|
|
395
424
|
});
|
|
396
425
|
}, []);
|
|
426
|
+
react.useEffect(() => {
|
|
427
|
+
const previousGroups = refArrayGroups.current;
|
|
428
|
+
const currentGroups = new Map();
|
|
429
|
+
state.groups.forEach((group) => {
|
|
430
|
+
currentGroups.set(group.uuid, group);
|
|
431
|
+
if (previousGroups.get(group.uuid) !== group) {
|
|
432
|
+
group.subscribe(subscriber);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
refArrayGroups.current = currentGroups;
|
|
436
|
+
}, [state.groups]);
|
|
397
437
|
const disable = react.useCallback(() => {
|
|
398
438
|
setState((state) => ({ ...state, disabled: true }));
|
|
399
439
|
}, []);
|
|
@@ -417,29 +457,36 @@ function useFormArray(options, validators) {
|
|
|
417
457
|
...state,
|
|
418
458
|
...refactorForGroups(groups, state.validators)
|
|
419
459
|
}));
|
|
420
|
-
|
|
460
|
+
refArrayValue.current = groups;
|
|
421
461
|
}, []);
|
|
422
462
|
const push = react.useCallback((group) => {
|
|
463
|
+
refArrayGroups.current.set(group.uuid, group);
|
|
464
|
+
group.subscribe(subscriber);
|
|
423
465
|
setState((state) => ({
|
|
424
466
|
...state,
|
|
425
467
|
...refactorForGroups([...state.groups, group], state.validators)
|
|
426
468
|
}));
|
|
427
469
|
}, []);
|
|
428
470
|
const merge = react.useCallback((groups) => {
|
|
471
|
+
groups.forEach((group) => {
|
|
472
|
+
group.subscribe(subscriber);
|
|
473
|
+
refArrayGroups.current.set(group.uuid, group);
|
|
474
|
+
});
|
|
429
475
|
setState((state) => ({
|
|
430
476
|
...state,
|
|
431
477
|
...refactorForGroups([...state.groups, ...groups], state.validators)
|
|
432
478
|
}));
|
|
433
479
|
}, []);
|
|
434
480
|
const remove = react.useCallback(({ uuid }) => {
|
|
481
|
+
refArrayGroups.current.delete(uuid);
|
|
435
482
|
setState((state) => ({
|
|
436
483
|
...state,
|
|
437
484
|
...refactorForGroups(state.groups.filter((group) => group.uuid !== uuid), state.validators)
|
|
438
485
|
}));
|
|
439
486
|
}, []);
|
|
440
487
|
const findByUuid = react.useCallback((uuid) => {
|
|
441
|
-
return
|
|
442
|
-
}, [
|
|
488
|
+
return refArrayGroups.current.get(uuid);
|
|
489
|
+
}, []);
|
|
443
490
|
const setValidators = react.useCallback((validators) => {
|
|
444
491
|
setState((state) => ({
|
|
445
492
|
...state,
|
|
@@ -454,9 +501,10 @@ function useFormArray(options, validators) {
|
|
|
454
501
|
return helpers.someErrors(state.errors, keys);
|
|
455
502
|
}, [state.errors]);
|
|
456
503
|
const reset = react.useCallback(() => {
|
|
504
|
+
refArrayValue.current.forEach((group) => group.reset());
|
|
457
505
|
setState((state) => ({
|
|
458
506
|
...state,
|
|
459
|
-
...refactorForGroups(
|
|
507
|
+
...refactorForGroups(refArrayValue.current, state.validators)
|
|
460
508
|
}));
|
|
461
509
|
}, []);
|
|
462
510
|
return {
|
|
@@ -608,42 +656,53 @@ function refactorForValid(controls, validators) {
|
|
|
608
656
|
};
|
|
609
657
|
}
|
|
610
658
|
function checkAllSuccess(status) {
|
|
611
|
-
return status.
|
|
659
|
+
return status.every((value) => value);
|
|
612
660
|
}
|
|
613
661
|
function checkPartialSuccess(status) {
|
|
614
|
-
return status.
|
|
662
|
+
return status.some((value) => value);
|
|
663
|
+
}
|
|
664
|
+
function arraysShallowEqual(a, b) {
|
|
665
|
+
if (a === b) {
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
if (a.length !== b.length) {
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
for (let i = 0; i < a.length; i++) {
|
|
672
|
+
if (a[i] !== b[i]) {
|
|
673
|
+
return false;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return true;
|
|
615
677
|
}
|
|
616
678
|
function useFormGroup(options, validators) {
|
|
617
679
|
const formGroup = helpers.createFormGroupOptions(options, validators);
|
|
618
|
-
const
|
|
619
|
-
|
|
620
|
-
touched: false,
|
|
621
|
-
value: false,
|
|
622
|
-
visual: false
|
|
623
|
-
});
|
|
680
|
+
const refControls = react.useRef(formGroup.controls);
|
|
681
|
+
refControls.current = formGroup.controls;
|
|
624
682
|
const formGroupStatus = react.useMemo(() => {
|
|
625
683
|
const dirty = [];
|
|
684
|
+
const disabled = [];
|
|
685
|
+
const focused = [];
|
|
626
686
|
const touched = [];
|
|
627
687
|
const value = [];
|
|
628
|
-
const visual = [];
|
|
629
688
|
Object.values(formGroup.controls).forEach((control) => {
|
|
630
689
|
dirty.push(control.dirty);
|
|
690
|
+
disabled.push(control.disabled);
|
|
691
|
+
focused.push(control.focused);
|
|
631
692
|
touched.push(control.touched);
|
|
632
693
|
value.push(control.value);
|
|
633
|
-
visual.push(control.disabled);
|
|
634
|
-
visual.push(control.focused);
|
|
635
694
|
});
|
|
636
695
|
return {
|
|
637
696
|
dirty,
|
|
697
|
+
disabled,
|
|
698
|
+
focused,
|
|
638
699
|
touched,
|
|
639
|
-
value
|
|
640
|
-
visual
|
|
700
|
+
value
|
|
641
701
|
};
|
|
642
702
|
}, [formGroup.controls]);
|
|
643
703
|
const [state, setState] = react.useState(() => {
|
|
644
704
|
return {
|
|
645
705
|
...refactorForValid(formGroup.controls, formGroup.validators),
|
|
646
|
-
controls: formGroup.controls,
|
|
647
706
|
dirties: checkAllSuccess(formGroupStatus.dirty),
|
|
648
707
|
dirty: checkPartialSuccess(formGroupStatus.dirty),
|
|
649
708
|
touched: checkPartialSuccess(formGroupStatus.touched),
|
|
@@ -652,75 +711,65 @@ function useFormGroup(options, validators) {
|
|
|
652
711
|
value: helpers.controlsToValue(formGroup.controls)
|
|
653
712
|
};
|
|
654
713
|
});
|
|
714
|
+
const refPrevFormGroupStatus = react.useRef(null);
|
|
655
715
|
react.useEffect(() => {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
controls: formGroup.controls,
|
|
661
|
-
value: helpers.controlsToValue(formGroup.controls)
|
|
662
|
-
}));
|
|
663
|
-
}
|
|
664
|
-
else {
|
|
665
|
-
formInitialized.current.value = true;
|
|
666
|
-
}
|
|
667
|
-
}, formGroupStatus.value);
|
|
668
|
-
react.useEffect(() => {
|
|
669
|
-
if (formInitialized.current.dirty) {
|
|
670
|
-
setState((state) => ({
|
|
671
|
-
...state,
|
|
672
|
-
controls: formGroup.controls,
|
|
673
|
-
dirty: checkPartialSuccess(formGroupStatus.dirty),
|
|
674
|
-
dirties: checkAllSuccess(formGroupStatus.dirty)
|
|
675
|
-
}));
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
formInitialized.current.dirty = true;
|
|
679
|
-
}
|
|
680
|
-
}, formGroupStatus.dirty);
|
|
681
|
-
react.useEffect(() => {
|
|
682
|
-
if (formInitialized.current.touched) {
|
|
683
|
-
setState((state) => ({
|
|
684
|
-
...state,
|
|
685
|
-
controls: formGroup.controls,
|
|
686
|
-
touched: checkPartialSuccess(formGroupStatus.touched),
|
|
687
|
-
toucheds: checkAllSuccess(formGroupStatus.touched)
|
|
688
|
-
}));
|
|
689
|
-
}
|
|
690
|
-
else {
|
|
691
|
-
formInitialized.current.touched = true;
|
|
692
|
-
}
|
|
693
|
-
}, formGroupStatus.touched);
|
|
694
|
-
react.useEffect(() => {
|
|
695
|
-
if (formInitialized.current.visual) {
|
|
696
|
-
setState((state) => ({
|
|
697
|
-
...state,
|
|
698
|
-
controls: formGroup.controls
|
|
699
|
-
}));
|
|
716
|
+
const formGroupPrev = refPrevFormGroupStatus.current;
|
|
717
|
+
refPrevFormGroupStatus.current = formGroupStatus;
|
|
718
|
+
if (!formGroupPrev) {
|
|
719
|
+
return;
|
|
700
720
|
}
|
|
701
|
-
|
|
702
|
-
|
|
721
|
+
const valueChanged = !arraysShallowEqual(formGroupPrev.value, formGroupStatus.value);
|
|
722
|
+
const dirtyChanged = !arraysShallowEqual(formGroupPrev.dirty, formGroupStatus.dirty);
|
|
723
|
+
const touchedChanged = !arraysShallowEqual(formGroupPrev.touched, formGroupStatus.touched);
|
|
724
|
+
const disabledChanged = !arraysShallowEqual(formGroupPrev.disabled, formGroupStatus.disabled);
|
|
725
|
+
const focusedChanged = !arraysShallowEqual(formGroupPrev.focused, formGroupStatus.focused);
|
|
726
|
+
if (!valueChanged &&
|
|
727
|
+
!dirtyChanged &&
|
|
728
|
+
!touchedChanged &&
|
|
729
|
+
!disabledChanged &&
|
|
730
|
+
!focusedChanged) {
|
|
731
|
+
return;
|
|
703
732
|
}
|
|
704
|
-
|
|
733
|
+
setState((state) => {
|
|
734
|
+
const next = { ...state };
|
|
735
|
+
if (valueChanged) {
|
|
736
|
+
const validResult = refactorForValid(refControls.current, state.validators);
|
|
737
|
+
next.errors = validResult.errors;
|
|
738
|
+
next.valid = validResult.valid;
|
|
739
|
+
next.value = helpers.controlsToValue(refControls.current);
|
|
740
|
+
}
|
|
741
|
+
if (dirtyChanged) {
|
|
742
|
+
next.dirty = checkPartialSuccess(formGroupStatus.dirty);
|
|
743
|
+
next.dirties = checkAllSuccess(formGroupStatus.dirty);
|
|
744
|
+
}
|
|
745
|
+
if (touchedChanged) {
|
|
746
|
+
next.touched = checkPartialSuccess(formGroupStatus.touched);
|
|
747
|
+
next.toucheds = checkAllSuccess(formGroupStatus.touched);
|
|
748
|
+
}
|
|
749
|
+
return next;
|
|
750
|
+
});
|
|
751
|
+
});
|
|
705
752
|
const setValidators = react.useCallback((validators) => {
|
|
706
753
|
setState((state) => ({
|
|
707
754
|
...state,
|
|
708
|
-
...refactorForValid(
|
|
755
|
+
...refactorForValid(refControls.current, validators),
|
|
756
|
+
validators
|
|
709
757
|
}));
|
|
710
758
|
}, []);
|
|
711
759
|
const setValue = react.useCallback((value) => {
|
|
712
760
|
Object.entries(value).forEach(([key, valueControl]) => {
|
|
713
|
-
const formControl =
|
|
761
|
+
const formControl = refControls.current[key];
|
|
714
762
|
formControl?.setValue(valueControl);
|
|
715
763
|
});
|
|
716
764
|
}, []);
|
|
717
765
|
const reset = react.useCallback(() => {
|
|
718
|
-
Object.values(
|
|
766
|
+
Object.values(refControls.current).forEach((control) => {
|
|
719
767
|
control.reset();
|
|
720
768
|
});
|
|
721
769
|
}, []);
|
|
722
770
|
return {
|
|
723
771
|
...state,
|
|
772
|
+
controls: formGroup.controls,
|
|
724
773
|
error: state.errors[0],
|
|
725
774
|
invalid: !state.valid,
|
|
726
775
|
pristine: !state.dirty,
|
|
@@ -736,16 +785,31 @@ function useFormGroup(options, validators) {
|
|
|
736
785
|
|
|
737
786
|
function useInputRefControl(options) {
|
|
738
787
|
const formRef = useInputControl(options);
|
|
788
|
+
const setValueRef = react.useRef(options.setValue);
|
|
789
|
+
setValueRef.current = options.setValue;
|
|
739
790
|
react.useEffect(() => {
|
|
740
|
-
formRef.elementRef?.current
|
|
791
|
+
const element = formRef.elementRef?.current;
|
|
792
|
+
if (!element) {
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
const handleFocus = () => {
|
|
741
796
|
formRef.focus();
|
|
742
|
-
}
|
|
743
|
-
|
|
797
|
+
};
|
|
798
|
+
const handleBlur = () => {
|
|
744
799
|
formRef.blur();
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
800
|
+
};
|
|
801
|
+
const handleChange = (event) => {
|
|
802
|
+
const target = event.target;
|
|
803
|
+
setValueRef.current(formRef, target.value);
|
|
804
|
+
};
|
|
805
|
+
element.addEventListener('focus', handleFocus);
|
|
806
|
+
element.addEventListener('blur', handleBlur);
|
|
807
|
+
element.addEventListener('change', handleChange);
|
|
808
|
+
return () => {
|
|
809
|
+
element.removeEventListener('focus', handleFocus);
|
|
810
|
+
element.removeEventListener('blur', handleBlur);
|
|
811
|
+
element.removeEventListener('change', handleChange);
|
|
812
|
+
};
|
|
749
813
|
}, []);
|
|
750
814
|
return formRef;
|
|
751
815
|
}
|