Skip to content

Support custom base query hook (Expose createBaseQuery) #69

@awhite

Description

@awhite

Summary

I’d like the ability to configure a custom base query hook in place of the default useQuery from @tanstack/react-query. This would allow teams to define shared defaults and behaviors (e.g., auth tokens, retry logic, logging) in a single location and apply them across all queries.

Use Case

In my application, I have a wrapper around useQuery called useFooQuery which sets up some default config values we want to apply globally. I’d like to use this as the base hook for all queries we create.

Ideally, I would be able to do something like:

import { createBaseQuery } from 'react-query-kit';
import { useFooQuery } from './useFooQuery';

export const createFooQuery = (options) => createBaseQuery(options, useFooQuery);

However, createBaseQuery is currently not exported, so I’m unable to use this approach.

Proposed Solution

Expose createBaseQuery from the package so that consumers can create custom query factories using their own base hooks.

Alternatives Considered

  • Wrapping every individual query hook to inject custom defaults, but this adds unnecessary boilerplate and defeats the purpose of react-query-kit’s streamlined DX.
  • Forking the library to expose createBaseQuery, which we’d rather avoid.

Benefits

  • Promotes better abstraction and DRY code
  • Maintains compatibility with react-query-kit’s design while allowing for greater flexibility
  • Empowers teams to enforce consistent behavior across all query hooks

Let me know if this would be feasible or if you’d consider supporting this in the core API. Happy to provide a PR if helpful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions