How to reset form values after successful query invalidation
I have a component that calls uses
useQuery to fetch some initial form data. When the data is fetched, I pass it to a form component which calls useForm from React Hook Form with the data as the defaultValues. When submitting the form, I call a mutation. In that mutation's onSuccess, I invalidate the same query that fetched the initial data. I would like to call reset when the query is finished invalidating with the new defaultValues. Every example I've seen calls reset in the onSucess callback of the mutation. I don't want to reset until the query is finished invalidating though. Is there any way I can achieve this?1 Reply
inland-turquoise•3y ago
invalidateQueries returns a promise that's resolved after the invalidation is completed, so you can just await it.