MCPcopy Index your code
hub / github.com/jaredpalmer/formik / remove

Method remove

packages/formik/src/FieldArray.tsx:290–315  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

288 handleUnshift = (value: any) => () => this.unshift(value);
289
290 remove<T>(index: number): T {
291 // We need to make sure we also remove relevant pieces of `touched` and `errors`
292 let result: any;
293 this.updateArrayField(
294 // so this gets call 3 times
295 (array?: any[]) => {
296 const copy = array ? copyArrayLike(array) : [];
297 if (!result) {
298 result = copy[index];
299 }
300 if (isFunction(copy.splice)) {
301 copy.splice(index, 1);
302 }
303 // if the array only includes undefined values we have to return an empty array
304 return isFunction(copy.every)
305 ? copy.every(v => v === undefined)
306 ? []
307 : copy
308 : copy;
309 },
310 true,
311 true
312 );
313
314 return result as T;
315 }
316
317 handleRemove = (index: number) => () => this.remove<any>(index);
318

Callers 1

FieldArrayInnerClass · 0.95

Calls 2

isFunctionFunction · 0.90
copyArrayLikeFunction · 0.85

Tested by

no test coverage detected