Skip to content

Commit

Permalink
fix react-hook-form#1229 to trigger re-render for formState update (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 authored Mar 17, 2020
1 parent 5813b1f commit 8d998ab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/useFieldArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const useFieldArray = <
mapCurrentFieldsValueWithState();
if (readFormStateRef.current.dirty) {
isDirtyRef.current = true;
reRender();
}
commonTasks([
...allFields.current,
Expand Down Expand Up @@ -140,10 +141,12 @@ export const useFieldArray = <
touchedFieldsRef.current[name],
fillEmptyArray(value),
);
reRender();
}
};

const remove = (index?: number | number[]) => {
let shouldRender = false;
if (!isUndefined(index)) {
mapCurrentFieldsValueWithState();
}
Expand All @@ -165,6 +168,7 @@ export const useFieldArray = <
touchedFieldsRef.current[name],
index,
);
shouldRender = true;
}

if (readFormStateRef.current.dirty) {
Expand All @@ -173,6 +177,7 @@ export const useFieldArray = <
dirtyFieldsRef.current.delete(dirtyField);
}
});
shouldRender = true;
}

if (readFormStateRef.current.isValid && !validateSchemaIsValid) {
Expand Down Expand Up @@ -212,6 +217,10 @@ export const useFieldArray = <
}
}

shouldRender = true;
}

if (shouldRender) {
reRender();
}
};
Expand Down Expand Up @@ -244,6 +253,7 @@ export const useFieldArray = <
index,
fillEmptyArray(value),
);
reRender();
}
};

Expand All @@ -261,6 +271,7 @@ export const useFieldArray = <

if (readFormStateRef.current.touched && touchedFieldsRef.current[name]) {
swapArrayAt(touchedFieldsRef.current[name], indexA, indexB);
reRender();
}
};

Expand All @@ -278,6 +289,7 @@ export const useFieldArray = <

if (readFormStateRef.current.touched && touchedFieldsRef.current[name]) {
moveArrayAt(touchedFieldsRef.current[name], from, to);
reRender();
}
};

Expand Down

0 comments on commit 8d998ab

Please sign in to comment.