fateh999 / react-native-paper-form-builder

React Native Paper Form Builder with inbuilt Validation, dropdown, autocomplete, checkbox, switch and radio inputs.
MIT License
116 stars 25 forks source link

How do I load default values from a database? #36

Closed dk253 closed 3 years ago

dk253 commented 3 years ago

Please forgive me if this is obvious, but I cannot figure it out.

I'm using a hook to grab a user's profile from a database and I'd like to prefill the form from the returned data. How do I load that data into the form for the user to change?

Thanks for this, BTW... Great library.

fateh999 commented 3 years ago

You can use the defaultValues param in useForm hook and pass in the data there if you have the data before loading of the form, but i guess in your case you are getting data after the loading of the form you can use reset method and pass the values in it.

const {reset} = useForm();

dk253 commented 3 years ago

Thank you so much for your response! I think I solved it a different way. I'm using the "setValue" function from react-hook-form. I was just about to add this to this issue. Thanks for your patience!