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

Function setValues

src/logic/createFormControl.ts:950–985  ·  view source on GitHub ↗
(
    formValues,
    options = {},
  )

Source from the content-addressed store, hash-verified

948 _setValue(name, value, options, false);
949
950 const setValues: UseFormSetValues<TFieldValues> = (
951 formValues,
952 options = {},
953 ) => {
954 const updatedFormValues = isFunction(formValues)
955 ? (formValues as Function)(_formValues as TFieldValues)
956 : formValues;
957
958 if (!deepEqual(_formValues, updatedFormValues)) {
959 _formValues = {
960 ..._formValues,
961 ...updatedFormValues,
962 };
963
964 for (const fieldName of _names.mount) {
965 _setValue(
966 fieldName as FieldPath<TFieldValues>,
967 get(updatedFormValues, fieldName),
968 options,
969 true,
970 true,
971 );
972 }
973
974 _subjects.state.next({
975 ..._formState,
976 name: undefined,
977 type: undefined,
978 ...(_valuesSubscriberCount ? { values: _formValues } : {}),
979 });
980
981 if (options.shouldValidate) {
982 _setValid();
983 }
984 }
985 };
986
987 const onChange: ChangeHandler = async (event) => {
988 _state.mount = true;

Callers 6

FormFunction · 0.85
ChildFunction · 0.85
LoaderFunction · 0.85
FormFunction · 0.85
AppFunction · 0.85
ComponentFunction · 0.85

Calls 3

deepEqualFunction · 0.85
_setValueFunction · 0.85
_setValidFunction · 0.85

Tested by 6

FormFunction · 0.68
ChildFunction · 0.68
LoaderFunction · 0.68
FormFunction · 0.68
AppFunction · 0.68
ComponentFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…