TanStackT
TanStack2y ago
4 replies
worthy-azure

How to handle a function dependency of the query/mutation function?

Given a query or mutation where the query/mutation function depends itself on another function, will the query/mutation always run with the most up-to-date function? Should this be managed somehow? E.g.,

const myFunc = useMyFunc();
const mutation = useMutation({
  mutationFn: async () => {
    const myResult = await myFunc(); // <-- Will this always be up to date?
    const res = fetch(myResult.url);
    
    // ...

    return res.json()
  },
});
Was this page helpful?