Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: value from WatchObserver is always undefined #9503

Closed
1 task done
nichita-pasecinic opened this issue Dec 2, 2022 · 2 comments
Closed
1 task done

issue: value from WatchObserver is always undefined #9503

nichita-pasecinic opened this issue Dec 2, 2022 · 2 comments

Comments

@nichita-pasecinic
Copy link

Version Number

^7.39.7

Codesandbox/Expo snack

/

Steps to reproduce

value field return in info param from the watch callback is always undefined (even though the values field [first argument] is updated with the actual value)

Pretty simple to reproduce

  const formMethods = useForm<AddFormEntityTypeFieldsType>({
    mode: 'onTouched',
    resolver,
    defaultValues,
  });
  const { watch, setValue, reset, getValues } = formMethods;

  // ....

  useEffect(() => {
    const sub = watch((formValues, info) => {
      const { name: fieldName, type: eventType, value } = info;
      console.log(fieldName, ' changed: ', eventType, ', newValue: ', value);
    });
    // unsubscribe from watching fields change
    return () => {
      console.log('will unsubscribe');
      sub.unsubscribe();
    };
  }, [watch]);

Expected behaviour

value should be update with every triggered field update

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049
Copy link
Member

#2848

@nichita-pasecinic
Copy link
Author

@bluebill1049 sorry for not following template, hope this one follows it!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants