(index: number)
| 227 | }; |
| 228 | |
| 229 | const remove = (index: number): void => { |
| 230 | options.pendingAsyncValuesRef.current = null; |
| 231 | |
| 232 | options.updateFormState((prev) => { |
| 233 | if (prev.isSubmitting || !options.isFieldEditableInternal(fieldKey, prev)) { |
| 234 | return prev; |
| 235 | } |
| 236 | |
| 237 | const currentValues = getArrayFieldValues(prev.values, field); |
| 238 | if (index < 0 || index >= currentValues.length) { |
| 239 | return prev; |
| 240 | } |
| 241 | |
| 242 | const nextValuesArray = removeAtIndex(currentValues, index); |
| 243 | const nextValues = { |
| 244 | ...prev.values, |
| 245 | [field]: nextValuesArray as unknown as T[K], |
| 246 | }; |
| 247 | options.pendingAsyncValuesRef.current = nextValues; |
| 248 | |
| 249 | const nextTouched = removeAtIndex( |
| 250 | normalizeBooleanArray(prev.touched[fieldKey], currentValues.length, false), |
| 251 | index, |
| 252 | ); |
| 253 | const nextDirty = computeFieldDirty( |
| 254 | fieldKey, |
| 255 | nextValuesArray as T[keyof T], |
| 256 | options.initialValuesRef.current, |
| 257 | ); |
| 258 | |
| 259 | let nextErrors = prev.errors; |
| 260 | if (options.validateOnChange) { |
| 261 | nextErrors = options.runSyncValidationFiltered(nextValues, prev); |
| 262 | } else { |
| 263 | nextErrors = { |
| 264 | ...prev.errors, |
| 265 | [fieldKey]: remapFieldArrayErrors(prev.errors[fieldKey], currentValues.length, (errs) => |
| 266 | removeAtIndex(errs, index), |
| 267 | ), |
| 268 | }; |
| 269 | } |
| 270 | |
| 271 | removeFieldArrayKey(fieldKey, index, options.fieldArrayKeysRef); |
| 272 | |
| 273 | return { |
| 274 | ...prev, |
| 275 | values: nextValues, |
| 276 | errors: nextErrors, |
| 277 | submitError: undefined, |
| 278 | touched: { |
| 279 | ...prev.touched, |
| 280 | [fieldKey]: nextTouched, |
| 281 | }, |
| 282 | dirty: { |
| 283 | ...prev.dirty, |
| 284 | [fieldKey]: nextDirty, |
| 285 | }, |
| 286 | }; |
nothing calls this directly
no test coverage detected