Skip to content
Discussion options

You must be logged in to vote

What is the type of dataFromServer? It should warn you that it is possibly undefined, which should cascade to the fields.

The best practice for async initial values is to have an 'empty' version of your data while the request is pending. All strings are empty strings, all Dates are today, all numbers are zero etc.

It doesn't need to be recreated on every render since it's just a static fallback object, so you can place it outside of the component.

const form = useAppForm({
  defaultValues: dataFromServer ?? emptyValues
})

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tyler-boyd
Comment options

@LeCarbonator
Comment options

@tyler-boyd
Comment options

Answer selected by tyler-boyd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants