Repository: react-hook-form/react-hook-form
File: src/useForm.ts (TypeScript)

Code before:
  function getValues<TFieldName extends string, TFieldValue extends unknown>(
    name: TFieldName,
  ): TFieldName extends keyof TFieldValues
    ? UnpackNestedValue<TFieldValues>[TFieldName]
    : TFieldValue;
  function getValues<TFieldName extends keyof TFieldValues>(
    names: TFieldName[],
  ): UnpackNestedValue<Pick<TFieldValues, TFieldName>>;
  function getValues(payload?: string | string[]): unknown {
    if (isString(payload)) {
      return getFieldValue(fieldsRef, payload, unmountFieldsStateRef);
    }

    if (isArray(payload)) {
      return payload.reduce(
        (previous, name) => ({
          ...previous,
          [name]: getFieldValue(fieldsRef, name, unmountFieldsStateRef),
        }),
        {},
      );
    }

    return transformToNestObject({
      ...unmountFieldsStateRef.current,
      ...getFieldsValues(fieldsRef, unmountFieldsStateRef),
    });
  }

  const validateResolver = React.useCallback(
    (values = {}) => {
      resolverRef.current!(
        {
          ...defaultValuesRef.current,
          ...getValues(),
          ...values,
        },
        contextRef.current,
        isValidateAllFieldCriteria,
      ).then(({ errors }) => {
        const previousFormIsValid = isValidRef.current;
        isValidRef.current = isEmptyObject(errors);

        if (previousFormIsValid !== isValidRef.current) {
          reRender();
        }
      });
    },
    [isValidateAllFieldCriteria],
  );


Review comment (suggestion):
I will try to look into it later. It seems like `unmountFieldsStateRef` will be useless to pass on `getFieldsValues` beacause `fieldsRef` only contains the mounted fields that's why I made this changes so `getFieldValue` will only get the mounted fields' value.

Code after:
  function getValues<TFieldName extends string, TFieldValue extends unknown>(
    name: TFieldName,
  ): TFieldName extends keyof TFieldValues
    ? UnpackNestedValue<TFieldValues>[TFieldName]
    : TFieldValue;
  function getValues<TFieldName extends keyof TFieldValues>(
    names: TFieldName[],
  ): UnpackNestedValue<Pick<TFieldValues, TFieldName>>;
  function getValues(payload?: string | string[]): unknown {
    if (isString(payload)) {
      return getFieldValue(fieldsRef, payload, unmountFieldsStateRef);
    }

    if (isArray(payload)) {
      return payload.reduce(
        (previous, name) => ({
          ...previous,
          [name]: getFieldValue(fieldsRef, name, unmountFieldsStateRef),
        }),
        {},
      );
    }

    return getFieldsValues(fieldsRef, unmountFieldsStateRef);
  }

  const validateResolver = React.useCallback(
    (values = {}) => {
      resolverRef.current!(
        {
          ...defaultValuesRef.current,
          ...getValues(),
          ...values,
        },
        contextRef.current,
        isValidateAllFieldCriteria,
      ).then(({ errors }) => {
        const previousFormIsValid = isValidRef.current;
        isValidRef.current = isEmptyObject(errors);

        if (previousFormIsValid !== isValidRef.current) {
          reRender();
        }
      });
    },
    [isValidateAllFieldCriteria],
  );

  const removeFieldEventListener = React.useCallback(
    (field: Field, forceDelete?: boolean) =>
      findRemovedFieldAndRemoveListener(