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 #9509

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

issue: value from WatchObserver is always undefined #9509

nichita-pasecinic opened this issue Dec 3, 2022 · 2 comments
Labels
bug Something isn't working TS Typescript related issues

Comments

@nichita-pasecinic
Copy link

Version Number

^7.39.7

Codesandbox/Expo snack

https://codesandbox.io/s/react-hook-form-watch1-forked-pwiuwg?file=/src/App.js

Steps to reproduce

  1. Go to https://codesandbox.io/s/react-hook-form-watch1-forked-pwiuwg?file=/src/App.js
  2. Type something into name input
  3. see in console that value from info parameter is always undefined

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)

  const methods = useForm({
    // mode: "onBlur",
    // reValidateMode: "onBlur",
    defaultValues: {
      name: "name"
    }
  });
  const { watch } = methods;

  useEffect(() => {
    // value is allways undefined here
    const sub = watch((data, { name, type, value }) => {
      console.log("field: ", name, " type: ", type, " newValue: ", value);
    });
    return () => sub.unsubscribe();
  }, [watch]);

Expected behaviour

Value to get updated properly on every change.

What browsers are you seeing the problem on?

Chrome

Relevant log output

From codesandbox:


name field watched from outside:  namesss 
field:  name  type:  change  newValue:  undefined

name field watched from outside:  namessss 
field:  name  type:  change  newValue:  undefined

name field watched from outside:  namesssss 
field:  name  type:  change  newValue:  undefined

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049 bluebill1049 added question Further information is requested bug Something isn't working and removed question Further information is requested labels Dec 3, 2022
@bluebill1049
Copy link
Member

Screenshot 2022-12-03 at 10 06 51 pm

it's a type bug, we actually not supply the value... thanks for the bug report!

@bluebill1049 bluebill1049 added the TS Typescript related issues label Dec 3, 2022
@nichita-pasecinic
Copy link
Author

@bluebill1049 Thx for quick response, so the actual value should be read from firs argument (data), yes ?

Also a informative question, there is a lot of possible values for the type property (it could be undefined, changed, ....)
Where I could inform myself under what circumstances is each of them used ?

@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
bug Something isn't working TS Typescript related issues
Projects
None yet
Development

No branches or pull requests

2 participants