From 726ae30b7b8ebfd64af17bea9c9dd29b6ab27beb Mon Sep 17 00:00:00 2001 From: Paul Sachs <11449728+paul-sachs@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:30:14 -0400 Subject: [PATCH] Adding more docs (#208) Add missing docs on `createUnaryHooks` and sync with connect-docs repo https://github.com/connectrpc/connectrpc.com/pull/66 --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0efca755..11ada246 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Connect-Query is an expansion pack for [TanStack Query](https://tanstack.com/que - [Usage](#usage) - [Connect-Query API](#connect-query-api) - [`createQueryService`](#createqueryservice) + - [`createUnaryHooks`](#createunaryhooks) - [`TransportProvider`](#transportprovider) - [`useTransport`](#usetransport) - [`UnaryFunctions.createData`](#unaryfunctionscreatedata) @@ -121,8 +122,8 @@ export const ExampleService = { const $queryService = createQueryService({ service: ExampleService }); export const example = { - ...$queryService.say, - ...createUnaryHooks($queryService.say), + ...$queryService.example, + ...createUnaryHooks($queryService.example), }; ``` @@ -177,6 +178,10 @@ const example = { const { data, isLoading, ...etc } = useQuery(example.useQuery()); ``` +### `createUnaryHooks` + +This creates some helper functions for unary methods that automatically include the transport from context. It's a distinct function from `createQueryService` so the core function can be separate from specific React APIs. + ### `TransportProvider` > Note: This API can only be used with React @@ -280,7 +285,7 @@ const createUseMutationOptions: (options: { }; ``` -`createUseMutationOptions` is intended to be used with TanStack's [`useMutation`](https://tanstack.com/query/v4/docs/react/reference/useMutation) hook. The difference is that `createUseMutationOptions` is not a hook and doesn't read from `TransportProvider` for it's transport. +`createUseMutationOptions` is intended to be used with TanStack's [`useMutation`](https://tanstack.com/query/v4/docs/react/reference/useMutation) hook. The difference is that `createUseMutationOptions` is not a hook and doesn't read from `TransportProvider` for its transport. ### `UnaryFunctions.createUseInfiniteQueryOptions` @@ -308,7 +313,7 @@ const createUseInfiniteQueryOptions: >( }; ``` -`createUseInfiniteQueryOptions` is intended to be used with TanStack's [`useInfiniteQuery`](https://tanstack.com/query/v4/docs/react/reference/useInfiniteQuery) hook. The difference is that `createUseInfiniteQueryOptions` is not a hook and doesn't read from `TransportProvider` for it's transport. +`createUseInfiniteQueryOptions` is intended to be used with TanStack's [`useInfiniteQuery`](https://tanstack.com/query/v4/docs/react/reference/useInfiniteQuery) hook. The difference is that `createUseInfiniteQueryOptions` is not a hook and doesn't read from `TransportProvider` for its transport. ### `UnaryFunctions.getPartialQueryKey` @@ -553,7 +558,7 @@ That said, we encourage you to check out the [Connect protocol](https://connectr ### Do I have to use a code generator? -No. The code generator just calls [`createQueryService`](#createqueryservice) with the arguments already added, but you are free to do that yourself if you wish. +No. The code generator just calls [`createQueryService`](#createqueryservice) and [`createUnaryHooks`](#createunaryhooks) with the arguments already added, but you are free to do that yourself if you wish. ### What if I have a custom `Transport`? @@ -574,7 +579,7 @@ import { say } from "./gen/eliza-ElizaService_connectquery"; function prefetch() { return queryClient.prefetchQuery( - say.createUseQueryOptions({ sentence: "Hello" }), + say.createUseQueryOptions({ sentence: "Hello", transport: myTransport }), ); } ```