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

Function prepend

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

Source from the content-addressed store, hash-verified

199 };
200
201 const prepend = (
202 value:
203 | Partial<FieldArray<TFieldValues, TFieldArrayName>>
204 | Partial<FieldArray<TFieldValues, TFieldArrayName>>[],
205 options?: FieldArrayMethodProps,
206 ) => {
207 if (disabled) {
208 return;
209 }
210
211 const prependValue = convertToArrayPayload(cloneObject(value));
212 const updatedFieldArrayValues = prependAt(
213 control._getFieldArray(name),
214 prependValue,
215 );
216 control._names.focus = getFocusFieldName(name, 0, options);
217 ids.current = prependAt(ids.current, prependValue.map(generateId));
218 updateValues(updatedFieldArrayValues);
219 setFields(updatedFieldArrayValues);
220 control._setFieldArray(name, updatedFieldArrayValues, prependAt, {
221 argA: fillEmptyArray(value),
222 });
223 };
224
225 const remove = (index?: number | number[]) => {
226 if (disabled) {

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…