Skip to content
Discussion options

You must be logged in to vote

RHF initializes your form with the provided default values only ones when the useForm hook is first called with the provided defaultValues.

There're different approach you can choose to provide the async default values to your form. In your case, since there's only one async field value, you can utilize the resetField form method to "update" your default field value once you get it.

const { resetField } = useForm()

useEffect(() => {
  if (category) {
    resetField("favShow", { defaultValue: category })
  }
}, [resetField, category])

Check out this working codesandbox

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jt4000
Comment options

Answer selected by jt4000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants