TanStackT
TanStack3y ago
17 replies
sad-indigo

Is calling functions within `queryFn` a bad design?

We use a combination of zod, react-hook-form, and react-query to populate, validate, control, and save our forms. Currently we're doing something like this for populating the schema:
const { reset } = methods

const { data, status } = useQuery({
  queryKey: ['foobar', id],
  queryFn: async ({ signal }) => {
    const details = await foobar.get({ id }, signal)

    reset(details)

    return {
      details
    }
  }
})

Is calling reset from within
queryFn
a bad idea? Is there any point for me to return details if I never use the data object or care about its cache?
Was this page helpful?