@rolster/react-forms 18.11.4 → 18.12.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/dist/es/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { createFormControlOptions, createFormGroupOptions, createFormArrayOptions } from '@rolster/forms/arguments';
2
- import { controlIsValid, hasError, someErrors, groupIsValid, controlsAllChecked, controlsPartialChecked, controlsToValue, groupAllChecked, arrayIsValid, reduceControlsToArray } from '@rolster/forms/helpers';
2
+ import { controlIsValid, hasError, someErrors, groupIsValid, controlsToValue, controlsAllChecked, controlsPartialChecked, arrayIsValid, groupAllChecked, reduceControlsToArray } from '@rolster/forms/helpers';
3
3
  import { v4 } from 'uuid';
4
4
  import { useRef, useState, useEffect, useCallback } from 'react';
5
5
 
6
- class RolsterReactArrayControl {
6
+ class RolsterArrayControl {
7
7
  constructor(options) {
8
- this.initialValue = options.initialValue;
9
8
  this.uuid = options.uuid;
9
+ this.value = options.value;
10
+ this.initialValue = options.initialValue;
10
11
  this.focused = !!options.focused;
11
12
  this.unfocused = !this.focused;
12
13
  this.touched = !!options.touched;
@@ -15,36 +16,42 @@ class RolsterReactArrayControl {
15
16
  this.pristine = !this.dirty;
16
17
  this.disabled = !!options.disabled;
17
18
  this.enabled = !this.disabled;
18
- const { value, validators } = options;
19
- this.value = value;
20
- this.validators = validators;
21
- this.errors = validators ? controlIsValid({ value, validators }) : [];
19
+ this.valid = this.isValid(options.errors);
20
+ this.invalid = !this.valid;
21
+ this.wrong = this.touched && this.invalid;
22
+ this.errors = options.errors;
22
23
  this.error = this.errors[0];
24
+ this.validators = options.validators;
23
25
  }
24
26
  focus() {
25
- this.unfocused && this.refresh({ focused: true });
27
+ this.unfocused && this.refresh('focused', { focused: true });
26
28
  }
27
29
  blur() {
28
- this.focused && this.refresh({ focused: false, touched: true });
30
+ this.focused && this.refresh('focused', { focused: false, touched: true });
29
31
  }
30
32
  disable() {
31
- this.enabled && this.refresh({ disabled: true });
33
+ this.enabled && this.refresh('disabled', { disabled: true });
32
34
  }
33
35
  enable() {
34
- this.disabled && this.refresh({ disabled: false });
36
+ this.disabled && this.refresh('disabled', { disabled: false });
35
37
  }
36
38
  touch() {
37
- this.untouched && this.refresh({ touched: true });
39
+ this.untouched && this.refresh('touched', { touched: true });
38
40
  }
39
41
  setInitialValue(value) {
40
- this.initialValue = value;
41
- this.setValue(value);
42
+ const { validators } = this;
43
+ const errors = validators ? controlIsValid({ value, validators }) : [];
44
+ this.refresh('value', { dirty: false, errors, initialValue: value, value });
42
45
  }
43
46
  setValue(value) {
44
- this.refresh({ value });
47
+ const { validators } = this;
48
+ const errors = validators ? controlIsValid({ value, validators }) : [];
49
+ this.refresh('value', { dirty: true, errors, value });
45
50
  }
46
51
  setValidators(validators) {
47
- this.refresh({ validators });
52
+ const { value } = this;
53
+ const errors = validators ? controlIsValid({ value, validators }) : [];
54
+ this.refresh('validators', { errors, validators });
48
55
  }
49
56
  subscribe(subscriber) {
50
57
  this.subscriber = subscriber;
@@ -56,37 +63,37 @@ class RolsterReactArrayControl {
56
63
  return someErrors(this.errors, keys);
57
64
  }
58
65
  reset() {
59
- this.refresh({
66
+ const { initialValue: value, validators } = this;
67
+ const errors = validators ? controlIsValid({ value, validators }) : [];
68
+ this.refresh('reset', {
60
69
  dirty: false,
70
+ errors,
61
71
  touched: false,
62
- value: this.initialValue
72
+ value
63
73
  });
64
74
  }
65
- refresh(changes) {
66
- this.subscriber &&
67
- this.subscriber({
68
- ...this,
69
- ...changes,
70
- initialValue: this.initialValue
71
- });
75
+ isValid(errors) {
76
+ return errors.length === 0;
77
+ }
78
+ builder(options) {
79
+ return new RolsterArrayControl({ ...this, ...options });
80
+ }
81
+ refresh(action, options) {
82
+ this.subscriber && this.subscriber(action, this.builder(options));
72
83
  }
73
84
  }
74
- class RolsterArrayControl extends RolsterReactArrayControl {
85
+ class ReactRolsterArrayControl extends RolsterArrayControl {
75
86
  constructor(options) {
76
- super(options);
77
- this.valid = this.errors.length === 0;
78
- this.invalid = !this.valid;
79
- this.wrong = this.touched && this.invalid;
80
- }
81
- clone(options) {
82
- return new RolsterArrayControl(options);
87
+ const { value, validators } = options;
88
+ const errors = validators ? controlIsValid({ value, validators }) : [];
89
+ super({ ...options, errors });
83
90
  }
84
91
  }
85
92
  function rolsterArrayControl(options, validators) {
86
- const controlOptions = createFormControlOptions(options, validators);
87
- return new RolsterArrayControl({
88
- ...controlOptions,
89
- initialValue: controlOptions.value,
93
+ const _options = createFormControlOptions(options, validators);
94
+ return new ReactRolsterArrayControl({
95
+ ..._options,
96
+ initialValue: _options.value,
90
97
  uuid: v4()
91
98
  });
92
99
  }
@@ -100,49 +107,112 @@ function inputArrayControl(options, validators) {
100
107
  return rolsterArrayControl(options, validators);
101
108
  }
102
109
 
103
- class RolsterArrayGroup {
110
+ function replaceControl(controls, control) {
111
+ return Object.entries(controls).reduce((controls, [key, _control]) => {
112
+ if (_control.uuid === control.uuid) {
113
+ controls[key] = control;
114
+ }
115
+ return controls;
116
+ }, controls);
117
+ }
118
+
119
+ function refactorForValid$2(controls, validators) {
120
+ const errors = validators ? groupIsValid({ controls, validators }) : [];
121
+ return {
122
+ errors,
123
+ valid: errors.length === 0 && controlsAllChecked(controls, 'valid')
124
+ };
125
+ }
126
+ function refactorForControls$1(group, controls, action) {
127
+ switch (action) {
128
+ case 'focused':
129
+ case 'touched':
130
+ return {
131
+ touched: controlsPartialChecked(controls, 'touched'),
132
+ toucheds: controlsAllChecked(controls, 'touched')
133
+ };
134
+ case 'validators':
135
+ return refactorForValid$2(controls, group.validators);
136
+ case 'reset':
137
+ return {
138
+ ...refactorForValid$2(controls, group.validators),
139
+ dirty: controlsPartialChecked(controls, 'dirty'),
140
+ dirties: controlsAllChecked(controls, 'dirty'),
141
+ touched: controlsPartialChecked(controls, 'touched'),
142
+ toucheds: controlsAllChecked(controls, 'touched'),
143
+ value: controlsToValue(controls)
144
+ };
145
+ case 'list':
146
+ case 'value':
147
+ return {
148
+ ...refactorForValid$2(controls, group.validators),
149
+ dirty: controlsPartialChecked(controls, 'dirty'),
150
+ dirties: controlsAllChecked(controls, 'dirty'),
151
+ value: controlsToValue(controls)
152
+ };
153
+ default:
154
+ return {};
155
+ }
156
+ }
157
+ class BaseArrayGroup {
104
158
  constructor(options) {
105
- const { controls, resource, uuid, validators } = options;
106
- this.uuid = uuid;
107
- this.controls = controls;
108
- this.validators = validators;
109
- this.resource = resource;
110
- this.errors = validators ? groupIsValid({ controls, validators }) : [];
111
- this.error = this.errors[0];
112
- this.valid =
113
- this.errors.length === 0 && controlsAllChecked(controls, 'valid');
114
- this.invalid = !this.valid;
115
- this.dirty = controlsPartialChecked(controls, 'dirty');
116
- this.dirties = controlsAllChecked(controls, 'dirty');
117
- this.touched = controlsPartialChecked(controls, 'touched');
118
- this.toucheds = controlsAllChecked(controls, 'touched');
159
+ this.uuid = options.uuid;
160
+ this.controls = options.controls;
161
+ this.value = options.value;
162
+ this.resource = options.resource;
163
+ this.dirty = !!options.dirty;
164
+ this.dirties = !!options.dirties;
119
165
  this.pristine = !this.dirty;
120
166
  this.pristines = !this.dirties;
167
+ this.touched = !!options.touched;
168
+ this.toucheds = !!options.toucheds;
121
169
  this.untouched = !this.touched;
122
170
  this.untoucheds = !this.toucheds;
171
+ this.valid = !!options.valid;
172
+ this.invalid = !this.valid;
123
173
  this.wrong = this.touched && this.invalid;
124
- this.value = controlsToValue(controls);
125
- const subscriber = (options) => {
126
- this.refresh({
127
- controls: Object.entries(this.controls).reduce((controls, [key, control]) => {
128
- controls[key] =
129
- control.uuid === options.uuid ? control.clone(options) : control;
130
- return controls;
131
- }, {})
174
+ this.errors = options.errors;
175
+ this.error = this.errors[0];
176
+ this.validators = options.validators;
177
+ const subscriber = (action, control) => {
178
+ const controls = replaceControl(this.controls, control);
179
+ this.refresh(action, {
180
+ ...refactorForControls$1(this, controls, action),
181
+ controls
132
182
  });
133
183
  };
134
- Object.values(controls).forEach((control) => {
184
+ Object.values(this.controls).forEach((control) => {
135
185
  control.subscribe(subscriber);
136
186
  });
137
187
  }
138
- setValidators(validators) {
139
- this.refresh({ validators });
140
- }
141
188
  subscribe(subscriber) {
142
189
  this.subscriber = subscriber;
143
190
  }
144
- refresh(changes) {
145
- this.subscriber && this.subscriber({ ...this, ...changes });
191
+ setValidators(validators) {
192
+ this.refresh('validators', {
193
+ ...refactorForValid$2(this.controls, validators),
194
+ validators
195
+ });
196
+ }
197
+ refresh(action, options) {
198
+ this.subscriber &&
199
+ this.subscriber(action, new BaseArrayGroup({ ...this, ...options }));
200
+ }
201
+ }
202
+ class RolsterArrayGroup extends BaseArrayGroup {
203
+ constructor(options) {
204
+ const { controls, validators } = options;
205
+ const errors = validators ? groupIsValid({ controls, validators }) : [];
206
+ super({
207
+ ...options,
208
+ errors,
209
+ value: controlsToValue(controls),
210
+ dirties: controlsAllChecked(controls, 'dirty'),
211
+ dirty: controlsPartialChecked(controls, 'dirty'),
212
+ touched: controlsPartialChecked(controls, 'touched'),
213
+ toucheds: controlsAllChecked(controls, 'touched'),
214
+ valid: errors.length === 0 && controlsAllChecked(controls, 'valid')
215
+ });
146
216
  }
147
217
  }
148
218
  function formArrayGroup(options, validators) {
@@ -152,111 +222,102 @@ function formArrayGroup(options, validators) {
152
222
  });
153
223
  }
154
224
 
155
- class RolsterArrayList extends RolsterReactArrayControl {
225
+ class RolsterArrayList extends RolsterArrayControl {
156
226
  constructor(options) {
157
- const value = options.controls.map((controls) => controlsToValue(controls));
158
- super({ ...options, value });
159
- this.valueToControls = options.valueToControls;
160
- this.controls = options.controls;
227
+ const { controls, valueToControls, validators } = options;
228
+ const value = controls.map((controls) => controlsToValue(controls));
229
+ const errors = validators ? controlIsValid({ value, validators }) : [];
230
+ super({ ...options, errors, value });
231
+ this.valueToControls = valueToControls;
232
+ this.controls = controls;
161
233
  this.valid =
162
- this.errors.length === 0 &&
163
- this.controls.reduce((valid, controls) => valid && controlsAllChecked(controls, 'valid'), true);
234
+ errors.length === 0 &&
235
+ controls.reduce((valid, controls) => valid && controlsAllChecked(controls, 'valid'), true);
164
236
  this.invalid = !this.valid;
165
237
  this.wrong = this.touched && this.invalid;
166
- options.controls.forEach((controls) => {
167
- this.subscribeControls(controls);
238
+ controls.forEach((reactControls) => {
239
+ this._subscribe(reactControls);
168
240
  });
169
241
  }
170
242
  setValue(value) {
171
- this.refresh({
243
+ this.refresh('list', {
172
244
  controls: value.map((value) => this.valueToControls(value))
173
245
  });
174
246
  }
175
- clone(options) {
176
- return new RolsterArrayList(options);
177
- }
178
247
  push(controls) {
179
- this.refresh({
248
+ this.refresh('list', {
180
249
  controls: [...this.controls, controls]
181
250
  });
182
251
  }
183
252
  remove(controls) {
184
- this.refresh({
185
- controls: this.controls.filter((currentControls) => currentControls !== controls)
253
+ this.refresh('list', {
254
+ controls: this.controls.filter((_controls) => _controls !== controls)
255
+ });
256
+ }
257
+ builder(options) {
258
+ return new RolsterArrayList({
259
+ ...this,
260
+ ...options,
261
+ valueToControls: this.valueToControls
186
262
  });
187
263
  }
188
- refresh(changes) {
189
- super.refresh(changes);
264
+ refresh(action, options) {
265
+ super.refresh(action, options);
190
266
  }
191
- subscribeControls(newControls) {
192
- Object.values(newControls).forEach((control) => {
193
- control.subscribe((options) => {
194
- const controls = this.controls.map((_controls) => _controls !== newControls
267
+ _subscribe(reactControls) {
268
+ Object.values(reactControls).forEach((control) => {
269
+ control.subscribe((action, _control) => {
270
+ const _reactControls = this.controls.map((_controls) => reactControls !== _controls
195
271
  ? _controls
196
- : Object.entries(newControls).reduce((controls, [key, control]) => {
197
- controls[key] =
198
- control.uuid === options.uuid
199
- ? control.clone(options)
200
- : control;
201
- return controls;
202
- }, {}));
203
- this.refresh({ controls });
272
+ : replaceControl(reactControls, _control));
273
+ this.refresh(action, { controls: _reactControls });
204
274
  });
205
275
  });
206
276
  }
207
277
  }
208
- function formArrayList(valueToControls, options) {
278
+ function formArrayList(options) {
209
279
  const value = options?.value || [];
210
280
  return new RolsterArrayList({
211
281
  ...options,
212
- valueToControls,
213
- controls: value.map((value) => valueToControls(value)),
282
+ controls: value.map((value) => options.valueToControls(value)),
214
283
  initialValue: value,
215
284
  uuid: v4()
216
285
  });
217
286
  }
218
287
 
219
- var Language;
220
- (function (Language) {
221
- Language["English"] = "en";
222
- Language["French"] = "fr";
223
- Language["Portuguese"] = "pt";
224
- Language["Spanish"] = "es";
225
- })(Language || (Language = {}));
226
-
227
- Language.Spanish;
228
- let subscribers = [];
229
- function i18nSubscribe(subscriber) {
230
- subscribers.push(subscriber);
231
- return () => {
232
- subscribers = subscribers.filter((currentSubscriber) => subscriber !== currentSubscriber);
233
- };
234
- }
235
-
236
- function errorsInArray(groups, validators) {
237
- return validators ? arrayIsValid({ groups, validators }) : [];
238
- }
239
- function validStateInArray(groups, validators) {
240
- const errors = errorsInArray(groups, validators);
288
+ function refactorForValid$1(groups, validators) {
289
+ const errors = validators ? arrayIsValid({ groups, validators }) : [];
241
290
  return {
242
291
  errors,
243
292
  valid: errors.length === 0 && groupAllChecked(groups, 'valid')
244
293
  };
245
294
  }
246
- function replaceStateInArray(groups, validators) {
295
+ function refactorForGroups(groups, validators) {
247
296
  return {
248
- ...validStateInArray(groups, validators),
297
+ ...refactorForValid$1(groups, validators),
249
298
  groups,
250
299
  controls: groups.map(({ controls }) => controls),
251
300
  value: groups.map(({ controls }) => controlsToValue(controls))
252
301
  };
253
302
  }
303
+ function refactorForControls(state, groups, action) {
304
+ switch (action) {
305
+ case 'validators':
306
+ return refactorForValid$1(groups, state.validators);
307
+ case 'reset':
308
+ case 'list':
309
+ case 'value':
310
+ return refactorForGroups(groups, state.validators);
311
+ default:
312
+ return { groups };
313
+ }
314
+ }
254
315
  function useFormArray(options, validators) {
255
316
  const _options = createFormArrayOptions(options, validators);
256
317
  const groups = _options.groups || [];
257
318
  const initialValue = useRef(groups);
258
319
  const [state, setState] = useState({
259
- ...validStateInArray(groups, _options.validators),
320
+ ...refactorForValid$1(groups, _options.validators),
260
321
  controls: groups.map(({ controls }) => controls),
261
322
  dirty: false,
262
323
  dirties: false,
@@ -268,21 +329,14 @@ function useFormArray(options, validators) {
268
329
  validators: _options.validators
269
330
  });
270
331
  useEffect(() => {
271
- return i18nSubscribe(() => {
272
- setState((state) => ({
273
- ...state,
274
- errors: errorsInArray(state.groups, state.validators)
275
- }));
276
- });
277
- }, []);
278
- useEffect(() => {
279
- const subscriber = (options) => {
280
- setState((state) => ({
281
- ...state,
282
- ...replaceStateInArray(state.groups.map((group) => group.uuid === options.uuid
283
- ? new RolsterArrayGroup(options)
284
- : group), state.validators)
285
- }));
332
+ const subscriber = (action, group) => {
333
+ setState((state) => {
334
+ const groups = state.groups.map((_group) => _group.uuid === group.uuid ? group : _group);
335
+ return {
336
+ ...state,
337
+ ...refactorForControls(state, groups, action)
338
+ };
339
+ });
286
340
  };
287
341
  state.groups.forEach((group) => {
288
342
  group.subscribe(subscriber);
@@ -297,49 +351,49 @@ function useFormArray(options, validators) {
297
351
  const setValue = useCallback((groups) => {
298
352
  setState((state) => ({
299
353
  ...state,
300
- ...replaceStateInArray(groups, state.validators)
354
+ ...refactorForGroups(groups, state.validators)
301
355
  }));
302
356
  }, []);
303
357
  const setInitialValue = useCallback((groups) => {
304
358
  setState((state) => ({
305
359
  ...state,
306
- ...replaceStateInArray(groups, state.validators)
360
+ ...refactorForGroups(groups, state.validators)
307
361
  }));
308
362
  initialValue.current = groups;
309
363
  }, []);
310
364
  const push = useCallback((group) => {
311
365
  setState((state) => ({
312
366
  ...state,
313
- ...replaceStateInArray([...state.groups, group], state.validators)
367
+ ...refactorForGroups([...state.groups, group], state.validators)
314
368
  }));
315
369
  }, []);
316
370
  const merge = useCallback((groups) => {
317
371
  setState((state) => ({
318
372
  ...state,
319
- ...replaceStateInArray([...state.groups, ...groups], state.validators)
373
+ ...refactorForGroups([...state.groups, ...groups], state.validators)
320
374
  }));
321
375
  }, []);
322
376
  const remove = useCallback(({ uuid }) => {
323
377
  setState((state) => ({
324
378
  ...state,
325
- ...replaceStateInArray(state.groups.filter((group) => group.uuid !== uuid), state.validators)
326
- }));
327
- }, []);
328
- const reset = useCallback(() => {
329
- setState((state) => ({
330
- ...state,
331
- ...replaceStateInArray(initialValue.current, state.validators)
379
+ ...refactorForGroups(state.groups.filter((group) => group.uuid !== uuid), state.validators)
332
380
  }));
333
381
  }, []);
334
382
  const setValidators = useCallback((validators) => {
335
383
  setState((state) => ({
336
384
  ...state,
337
- ...validStateInArray(state.groups, validators),
385
+ ...refactorForValid$1(state.groups, validators),
338
386
  validators
339
387
  }));
340
388
  }, []);
341
389
  const hasError$1 = useCallback((key) => hasError(state.errors, key), [state.errors]);
342
390
  const someErrors$1 = useCallback((keys) => someErrors(state.errors, keys), [state.errors]);
391
+ const reset = useCallback(() => {
392
+ setState((state) => ({
393
+ ...state,
394
+ ...refactorForGroups(initialValue.current, state.validators)
395
+ }));
396
+ }, []);
343
397
  return {
344
398
  ...state,
345
399
  disable,
@@ -380,14 +434,6 @@ function useControl(options, validators) {
380
434
  validators: _options.validators
381
435
  });
382
436
  const elementRef = useRef(null);
383
- useEffect(() => {
384
- return i18nSubscribe(() => {
385
- setState((state) => ({
386
- ...state,
387
- errors: errorsInControl(state.value, state.validators)
388
- }));
389
- });
390
- }, []);
391
437
  const focus = useCallback(() => {
392
438
  setState((state) => ({ ...state, focused: true }));
393
439
  }, []);
@@ -473,11 +519,8 @@ function useInputControl(options, validators) {
473
519
  return useControl(options, validators);
474
520
  }
475
521
 
476
- function errorsInGroup(controls, validators) {
477
- return validators ? groupIsValid({ controls, validators }) : [];
478
- }
479
- function validStateInGroup(controls, validators) {
480
- const errors = errorsInGroup(controls, validators);
522
+ function refactorForValid(controls, validators) {
523
+ const errors = validators ? groupIsValid({ controls, validators }) : [];
481
524
  return {
482
525
  errors,
483
526
  valid: errors.length === 0 && controlsAllChecked(controls, 'valid')
@@ -486,8 +529,14 @@ function validStateInGroup(controls, validators) {
486
529
  function useFormGroup(options, validators) {
487
530
  const _options = createFormGroupOptions(options, validators);
488
531
  const { controls } = _options;
532
+ const firstEffects = useRef({
533
+ dirty: true,
534
+ disabledFocused: true,
535
+ touched: true,
536
+ value: true
537
+ });
489
538
  const [state, setState] = useState({
490
- ...validStateInGroup(controls, _options.validators),
539
+ ...refactorForValid(controls, _options.validators),
491
540
  controls,
492
541
  dirties: controlsAllChecked(controls, 'dirty'),
493
542
  dirty: controlsPartialChecked(controls, 'dirty'),
@@ -497,50 +546,62 @@ function useFormGroup(options, validators) {
497
546
  validators: _options.validators
498
547
  });
499
548
  useEffect(() => {
500
- return i18nSubscribe(() => {
549
+ if (!firstEffects.current.value) {
501
550
  setState((state) => ({
502
551
  ...state,
503
- errors: errorsInGroup(state.controls, state.validators)
552
+ ...refactorForValid(controls, state.validators),
553
+ controls,
554
+ value: controlsToValue(controls)
504
555
  }));
505
- });
506
- }, []);
507
- useEffect(() => {
508
- setState((state) => ({
509
- ...state,
510
- ...validStateInGroup(controls, state.validators),
511
- controls,
512
- value: controlsToValue(controls)
513
- }));
556
+ }
557
+ else {
558
+ firstEffects.current.value = false;
559
+ }
514
560
  }, reduceControlsToArray(controls, 'value'));
515
561
  useEffect(() => {
516
- setState((state) => ({
517
- ...state,
518
- controls
519
- }));
562
+ if (!firstEffects.current.disabledFocused) {
563
+ setState((state) => ({
564
+ ...state,
565
+ controls
566
+ }));
567
+ }
568
+ else {
569
+ firstEffects.current.disabledFocused = false;
570
+ }
520
571
  }, [
521
572
  ...reduceControlsToArray(controls, 'disabled'),
522
573
  ...reduceControlsToArray(controls, 'focused')
523
574
  ]);
524
575
  useEffect(() => {
525
- setState((state) => ({
526
- ...state,
527
- controls,
528
- dirty: controlsPartialChecked(controls, 'dirty'),
529
- dirties: controlsAllChecked(controls, 'dirty')
530
- }));
576
+ if (!firstEffects.current.dirty) {
577
+ setState((state) => ({
578
+ ...state,
579
+ controls,
580
+ dirty: controlsPartialChecked(controls, 'dirty'),
581
+ dirties: controlsAllChecked(controls, 'dirty')
582
+ }));
583
+ }
584
+ else {
585
+ firstEffects.current.dirty = false;
586
+ }
531
587
  }, reduceControlsToArray(controls, 'dirty'));
532
588
  useEffect(() => {
533
- setState((state) => ({
534
- ...state,
535
- controls,
536
- touched: controlsPartialChecked(controls, 'touched'),
537
- toucheds: controlsAllChecked(controls, 'touched')
538
- }));
589
+ if (!firstEffects.current.touched) {
590
+ setState((state) => ({
591
+ ...state,
592
+ controls,
593
+ touched: controlsPartialChecked(controls, 'touched'),
594
+ toucheds: controlsAllChecked(controls, 'touched')
595
+ }));
596
+ }
597
+ else {
598
+ firstEffects.current.touched = false;
599
+ }
539
600
  }, reduceControlsToArray(controls, 'touched'));
540
601
  const setValidators = useCallback((validators) => {
541
602
  setState((state) => ({
542
603
  ...state,
543
- ...validStateInGroup(state.controls, validators)
604
+ ...refactorForValid(state.controls, validators)
544
605
  }));
545
606
  }, []);
546
607
  const reset = useCallback(() => {