MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / moveFieldArrayKey

Function moveFieldArrayKey

packages/core/src/forms/internal/arrayState.ts:105–121  ·  view source on GitHub ↗
(
  field: keyof T,
  from: number,
  to: number,
  fieldArrayKeysRef: FieldArrayKeysRef<T>,
)

Source from the content-addressed store, hash-verified

103}
104
105function moveFieldArrayKey<T extends Record<string, unknown>>(
106 field: keyof T,
107 from: number,
108 to: number,
109 fieldArrayKeysRef: FieldArrayKeysRef<T>,
110): void {
111 const existing = [...(fieldArrayKeysRef.current[field] ?? [])];
112 if (from < 0 || to < 0 || from >= existing.length || to >= existing.length || from === to) {
113 return;
114 }
115 const [moved] = existing.splice(from, 1);
116 if (moved === undefined) {
117 return;
118 }
119 existing.splice(to, 0, moved);
120 fieldArrayKeysRef.current[field] = existing;
121}
122
123function remapFieldArrayErrors(
124 fieldError: FieldErrorValue | undefined,

Callers 1

moveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected