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

Function prepend

src/useFieldArray.ts:187–205  ·  view source on GitHub ↗
(
    value:
      | Partial<FieldArray<TFieldValues, TFieldArrayName>>
      | Partial<FieldArray<TFieldValues, TFieldArrayName>>[],
    options?: FieldArrayMethodProps,
  )

Source from the content-addressed store, hash-verified

185 };
186
187 const prepend = (
188 value:
189 | Partial<FieldArray<TFieldValues, TFieldArrayName>>
190 | Partial<FieldArray<TFieldValues, TFieldArrayName>>[],
191 options?: FieldArrayMethodProps,
192 ) => {
193 const prependValue = convertToArrayPayload(cloneObject(value));
194 const updatedFieldArrayValues = prependAt(
195 control._getFieldArray(name),
196 prependValue,
197 );
198 control._names.focus = getFocusFieldName(name, 0, options);
199 ids.current = prependAt(ids.current, prependValue.map(generateId));
200 updateValues(updatedFieldArrayValues);
201 setFields(updatedFieldArrayValues);
202 control._setFieldArray(name, updatedFieldArrayValues, prependAt, {
203 argA: fillEmptyArray(value),
204 });
205 };
206
207 const remove = (index?: number | number[]) => {
208 const updatedFieldArrayValues: Partial<

Callers 15

AppFunction · 0.85
ComponentFunction · 0.85
prepend.test.tsFile · 0.85
ComponentFunction · 0.85
FieldArrayFunction · 0.85
AppFunction · 0.85
ComponentFunction · 0.85
WatchUseFieldArrayFunction · 0.85
NestedArrayFunction · 0.85
UseFieldArrayUnregisterFunction · 0.85
UseFieldArrayFunction · 0.85

Calls 1

cloneObjectFunction · 0.85

Tested by 6

AppFunction · 0.68
ComponentFunction · 0.68
ComponentFunction · 0.68
FieldArrayFunction · 0.68
AppFunction · 0.68
ComponentFunction · 0.68