Populate fields initial values from API, and use "WatchableFormValue"

I can’t seem to figure out how to use the second argument of “useForm”, as described here: https://tinacms.org/docs/forms

In short, I need to populate the form data from an external API call, but the form seems to be generated before the api call, thus I can’t use “initialValues”.

I want to watch a variable for change, and populate the fields accordingly.

Other suggestions are welcome too, I tried using “useEffect” to wrap “useForm” but without success

Welcome @NiviJah!

Instead of passing in initialValues you could instead try using loadInitialValues to fetch the data:

useForm({
  loadInitialValues: () => my.api.request()
  // ...
})

That solved my issue, thank you!

2 Likes