Re-rendering Issue with Select function When Using TanStack Query and Formik #8557
Replies: 1 comment 3 replies
-
likely because
see: https://tkdodo.eu/blog/react-query-and-forms
generally, |
Beta Was this translation helpful? Give feedback.
-
Hey @TkDodo, thank you for creating such an amazing library, your efforts are truly appreciated!
I am encountering an issue where the select function is invoked every time the setValues function from Formik is called after fetching data via TanStack Query. This results in unnecessary re-renders and causes an infinite loop. Interestingly, this issue does not occur when using useState instead of Formik.
Additionally, the select function is triggered when the form fields are updated, causing the values to be stored in Formik again. I am trying to understand why this happens and if there’s a better solution to prevent this behaviour.
Code Example
const { data } = useQuery({
queryKey: ["getInvoice"],
queryFn: () => getInvoice(),
select: (updatedData) => {
InoviceForm.setValues(updatedData);
return updatedData;
},
});
Beta Was this translation helpful? Give feedback.
All reactions