You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the `createCustomClient()` function in the `create-custom-api.ts` file with no default services and only `setQueryData()` and `getQueryData()` callbacks
Copy file name to clipboardExpand all lines: website/versioned_docs/version-2.14.0/codegen/create-api-client-function.mdx
+45-30Lines changed: 45 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,30 +148,51 @@ the necessary `requestFn`, `baseUrl` and `queryClient` for React Hooks.
148
148
```
149
149
</TabItem>
150
150
<TabItemvalue="multiple-api-versions"label={<spanstyle={{verticalAlign: 'middle'}}>Multiple API versions and <em>React <code>Context</code></em></span>}>
151
-
This example demonstrates how to use multiple API clients with React Context. With the `context:` option
152
-
in CLI, you can generate an API client that retrieves `queryClient`, `requestFn`, and `baseUrl` from
153
-
React Context at render time.
151
+
In this example, we create multiple API clients that manage two different API versions, each with its own `QueryClient`.
152
+
This approach mounts and unmounts `QueryClient` instances during the lifecycle of the application.
154
153
155
-
:::tip React Compiler Compatibility
156
-
Creating the API client **outside of the component** with the `context:` option makes hooks static,
157
-
allowing React Compiler to optimize them. If you create the client inside `useMemo`, hooks become
158
-
dynamic and cannot be optimized by React Compiler.
159
-
:::
154
+
This setup is particularly useful when you need to work with different API versions simultaneously, or when you're in the process
155
+
of migrating from one API version to another.
160
156
161
157
```tsx title="src/MultipleAPIClientsApp.tsx"
162
-
import { createAPIClientascreateAPIClientV1, APIClientContextV1} from'./api-v1'; // generated with context:APIClientContextV1
163
-
import { createAPIClientascreateAPIClientV2, APIClientContextV2} from'./api-v2'; // generated with context:APIClientContextV2
0 commit comments