React-hook-form: Integrate with global state

Created on 31 Dec 2019  路  1Comment  路  Source: react-hook-form/react-hook-form

I read the part of the documentation about integration with global state and I didn't understand.
I'm not using connect from react-redux, I'm using the new hooks style like useDispatch.

Take a look at part of my code (It's not compiling, just to see the actual code)
https://codesandbox.io/s/react-5rfno

The goal here is to connect with my redux and get a defaultValue to each of my inputs.

Based on the code above, how can I connect the form to my redux?

Most helpful comment

I'm not an expert with the library but i was able to get your solution working

https://codesandbox.io/s/react-n9kfm

It looks like you were trying to make your inputs controlled, using useState and value={state}.
This is not necessary to do with this library, as it handles the value for you using the ref. (uncontrolled input). You can dispatch inside either onSubmit or inside an individual onChange.

>All comments

I'm not an expert with the library but i was able to get your solution working

https://codesandbox.io/s/react-n9kfm

It looks like you were trying to make your inputs controlled, using useState and value={state}.
This is not necessary to do with this library, as it handles the value for you using the ref. (uncontrolled input). You can dispatch inside either onSubmit or inside an individual onChange.

Was this page helpful?
0 / 5 - 0 ratings