MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / swap

Function swap

src/useFieldArray.ts:244–260  ·  view source on GitHub ↗
(indexA: number, indexB: number)

Source from the content-addressed store, hash-verified

242 };
243
244 const swap = (indexA: number, indexB: number) => {
245 const updatedFieldArrayValues = control._getFieldArray(name);
246 swapArrayAt(updatedFieldArrayValues, indexA, indexB);
247 swapArrayAt(ids.current, indexA, indexB);
248 updateValues(updatedFieldArrayValues);
249 setFields(updatedFieldArrayValues);
250 control._setFieldArray(
251 name,
252 updatedFieldArrayValues,
253 swapArrayAt,
254 {
255 argA: indexA,
256 argB: indexB,
257 },
258 false,
259 );
260 };
261
262 const move = (from: number, to: number) => {
263 const updatedFieldArrayValues = control._getFieldArray(name);

Callers 13

AppFunction · 0.85
swap.test.tsFile · 0.85
ComponentFunction · 0.85
AppFunction · 0.85
WatchUseFieldArrayFunction · 0.85
NestedArrayFunction · 0.85
UseFieldArrayUnregisterFunction · 0.85
UseFieldArrayFunction · 0.85
NestedArrayFunction · 0.85
NestedArrayFunction · 0.85

Calls

no outgoing calls

Tested by 3

AppFunction · 0.68
ComponentFunction · 0.68
AppFunction · 0.68