Skip to content

Commit 5f2bcd4

Browse files
committed
Fix setState with child forms
1 parent 85b7741 commit 5f2bcd4

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/form.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,8 @@ export class FormState<T extends object, State = DefaultState, Error extends str
246246
this.setValueInternal(key, value, dirty, validate, isDefault, notifyChild, notifyParent, fireAny);
247247
} else {
248248
// Compare value and existing value/defaultValue which determines dirty
249-
let dirty = isDefault ? value !== this.values[key] : value !== this.defaultValues[key];
250-
251-
// Do not set if already set
252-
if (((isDefault && this.defaultValues[key] === value) || (!isDefault && this.values[key] === value)) && this.dirtyMap[key] === dirty) {
249+
let dirty = value !== (isDefault ? this.values[key] : this.defaultValues[key]);
250+
if ((isDefault ? this.defaultValues[key] : this.values[key]) === value && this.dirtyMap[key] === dirty) {
253251
return;
254252
}
255253

@@ -453,7 +451,7 @@ export class FormState<T extends object, State = DefaultState, Error extends str
453451
this._state = newState;
454452

455453
let c = Object.keys(this.values) as (keyof T)[];
456-
if (notifyChild) c.forEach((e) => (this.childMap[e as any] as ChildFormState<T, any, State, Error>).setState(newState, true, false));
454+
if (notifyChild) c.forEach((e) => (this.childMap[e as any] as ChildFormState<T, any, State, Error>)?.setState(newState, true, false));
457455

458456
c.forEach((e) => this.fireListeners(e));
459457
this.fireAnyListeners();

0 commit comments

Comments
 (0)