MCPcopy
hub / github.com/react-hook-form/react-hook-form / swap

Function swap

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

Source from the content-addressed store, hash-verified

268 };
269
270 const swap = (indexA: number, indexB: number) => {
271 if (disabled) {
272 return;
273 }
274
275 const updatedFieldArrayValues = control._getFieldArray(name);
276 swapArrayAt(updatedFieldArrayValues, indexA, indexB);
277 swapArrayAt(ids.current, indexA, indexB);
278 updateValues(updatedFieldArrayValues);
279 setFields(updatedFieldArrayValues);
280 control._setFieldArray(
281 name,
282 updatedFieldArrayValues,
283 swapArrayAt,
284 {
285 argA: indexA,
286 argB: indexB,
287 },
288 false,
289 );
290 };
291
292 const move = (from: number, to: number) => {
293 if (disabled) {

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…