Data from React Query don't show in useForm's default values #11946
Replies: 4 comments 1 reply
-
You can use the
|
Beta Was this translation helpful? Give feedback.
-
For data that comes in "later" than the initial render/reactive values, which may change on background refetch, consider using the |
Beta Was this translation helpful? Give feedback.
-
Does Also, passing the You could set your If you want to continue to use
const queryArgs = { ... }
const { fetchQuery } = useQueryClient() ;; for default-values
const { data } = useQuery(queryArgs) ;; for up-to-date validation
const defaultValues = () => fetchQuery(queryArgs) ;; fetchQuery returns a promise
const resolver = (values) => data.includes(values.name) && "Name taken" ;; needs latest data
const { ... } = useForm({ defaultValues, resolver })
const { isLoading } = useFormState()
if (isLoading) {
return <Spinner> Loading initial data... </Spinner>
} else {
... ;; form is ready
} |
Beta Was this translation helpful? Give feedback.
-
Note for anyone else looking: It seems like if you set What I am seeing is that if you set Cannot assign to read only property 'name' of function <...your loader...> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a page where I want to edit user's details and I download the user's data from React Query + axios. Then I have a Form with inputs where I want to show the downloaded data (name, address, etc), but when I tell the useForm that I want anything from this data in defaultValues, all the inputs show empty.
How can I overcome this and be able to show the data in each respective input for the user to edit?
Beta Was this translation helpful? Give feedback.
All reactions