Skip to content
Source
Sign inSign up
TanStack/form

fix: bump array version on reset so array fields re-render #2243

Openhemraj-007(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2243/headopened

Showing 4 changed files with 38 additions and 0 deletions (loading 1).

x
0 of 4 viewed, 4 left
8 additions and 0 deletions.changeset/fix-array-reset-rerender.mdAdded
View file
@@ -0,0 +1,8 @@
+---
+'@tanstack/form-core': patch
+'@tanstack/react-form': patch
+---
+​
+Bump `_arrayVersion` when resetting array fields so adapters re-render after `form.reset()` or `form.resetField()` changes array length.
+​
+Fixes #2228
13 additions and 0 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -1847,6 +1847,15 @@
fieldMetaBase,
+​
+ const helper = metaHelper(this)
+ for (const fieldKey of Object.keys(
+ this.fieldInfo,
+ ) as DeepKeys<TFormData>[]) {
+ if (Array.isArray(this.getFieldValue(fieldKey))) {
+ helper.bumpArrayVersion(fieldKey)
+ }
+ }