Skip to content

Generic TanStack Query Adapters #3629

Open

Description

@KATT

It would be very helpful to support TanStack Query in a library-agnostic way instead of react specific way.

Originally posted by @ozum in #3496 (comment)

TRP-57

Activity

  1. jrmyio commented on Feb 1, 2023

    @jrmyio

    I think I just figured out I am in need of the this.

    I am using trpc outside a component via:
    await trpc.products.list.query()) when I was searching for a way to set a timeout on the query but it seems there are only the options context and signal.

    What I really need are the options from @tanstack/query QueryClient :
    https://tanstack.com/query/latest/docs/react/reference/QueryClient

    I guess this issue is exactly about this?

    I am currently working around the issue with this:

    import type { FetchQueryOptions } from '@tanstack/query-core';
    import type { QueryClient } from '@tanstack/react-query';
    
    /**
     * This is a temporary work around until we can use TRPC and Tanstack Query
     * outside React directly:
     * https://github.com/trpc/trpc/issues/3629
     */
    export const queryTRPCViaReactQuery = async <
        Q extends (arg: any, { signal }: { signal?: AbortSignal }) => Promise<any>,
    >({
        queryClient,
        id,
        query,
        params = undefined,
        options = {},
    }: {
        queryClient: QueryClient;
        id: string;
        query: Q;
        params?: Parameters<Q>[0];
        options?: FetchQueryOptions<any>;
    }): Promise<ReturnType<Q>> => {
        const controller = new AbortController();
        const signal = controller.signal;
    
        try {
            return await queryClient.fetchQuery([id, params], async () => query(params, { signal }), {
                ...options,
            });
        } catch (error) {
            controller.abort();
            throw error;
        }
    };
  2. changed the title [-]Generic TanStack Query Adapters[/-] [+][TRP-57] Generic TanStack Query Adapters[/+] on May 25, 2023
  3. changed the title [-][TRP-57] Generic TanStack Query Adapters[/-] [+]Generic TanStack Query Adapters[/+] on May 25, 2023
  4. ArjunCodess commented on Sep 20, 2026

    @ArjunCodess

    hi, is this still wanted? the issue is from 2023 and on current main it still is not there: @trpc/tanstack-react-query exists and is react-only. i'd actually extract a framework-agnostic adapter for vue/solid/core if you still want that. should i send a pr, or did the plan change?

  5. KATT commented on Nov 2, 2026

    @KATT
    MemberAuthor

    🤖 This is happening in v12 (the v12 branch): one TanStack Query package plus experimental Solid, Vue, Svelte, Angular, Preact and Lit adapters. https://v12.trpc.io/v12/docs/integrations/tanstack-query. v12 isn't released yet and there's no ETA. Thanks @ArjunCodess for offering; v11 won't get this.

  6. added
    next-major/definite
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-major/definite

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions