/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react-query/src/internals/trpcResult.ts
55 строк
1 KB
Julius Marminge
feat: `queryOptions` API (#5913)
16 окт 2024, 17:33
Не верифицирован
16 окт 2024, 17:33
26ac97c
Код
Авторство
О чём код?
import type { QueryClient } from '@tanstack/react-query'; import * as React from 'react'; import type { TRPCQueryOptionsResult } from '../shared'; import type { TRPCHookResult } from '../shared/hooks/types'; import type { TRPCQueryKey } from './getQueryKey'; export function createTRPCOptionsResult(value: { path: readonly string[]; }): TRPCQueryOptionsResult['trpc'] { const path = value.path.join('.'); return { path, }; } /** * Makes a stable reference of the `trpc` prop */ export function useHookResult(value: { path: readonly string[]; }): TRPCHookResult['trpc'] { const result = createTRPCOptionsResult(value); return React.useMemo(() => result, [result]); } /** * @internal */ export async function buildQueryFromAsyncIterable( asyncIterable: AsyncIterable<unknown>, queryClient: QueryClient, queryKey: TRPCQueryKey, ) { const queryCache = queryClient.getQueryCache(); const query = queryCache.build(queryClient, { queryKey, }); query.setState({ data: [], status: 'success', }); const aggregate: unknown[] = []; for await (const value of asyncIterable) { aggregate.push(value); query.setState({ data: [...aggregate], }); } return aggregate; }