TanStackT
TanStack3y ago
4 replies
foolish-indigo

Custom query hook and type for placeholderData option

Hi! I'm currently trying to migrate from v3 to v5 and have an issue with defining the type for placeholderData option that I'm using with keepPreviousData helper function.

We've got our own basic UseQueryOption type defined with a few of the common options (e.g.
enabled
, keepPreviousData) that we use with our custom query hooks. Until now, keepPreviousData was simply a boolean, but now placeholderData is a generic type that depends on the response type.

What's the best way to type it? Right now, most of our custom query hooks are typed as:

// file with types
type UseQueryOptions = {
  enabled?: boolean
  keepPreviousData?: boolean
}

// file with hook
const useCustomQuery = (params: UseCustomQueryParams, options?: UseQueryOptions) => {
  ...
  return useQuery({...})
}


What's the best way to provide a type for placeholderData in UseQueryOptions?
Was this page helpful?