Skip to content

Commit ae9e2e0

Browse files
committed
Sync open source content 🐝 (from 581b5f4847acc2de8355da53f2fff94e16490bf3)
1 parent 1f2e842 commit ae9e2e0

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

docs/sdks/customize/typescript/react-hooks.mdx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,51 @@ The generated SDK with React Hooks has TanStack Query as a dependency that shoul
164164
The Speakeasy-generated TypeScript SDK bundles Zod for runtime type validation, and TanStack Query powers the React hooks. TanStack Query is required for the React hooks to function correctly.
165165
</Callout>
166166

167-
### Set up the React Query provider
167+
### Set up the providers
168168

169-
Add the TanStack Query provider to your React application:
169+
The generated React hooks require two providers to be set up in your application:
170+
171+
1. **QueryClientProvider** from TanStack Query for managing query state
172+
2. **SDK Provider** from your generated SDK for providing the API client instance
173+
174+
Add both providers to your React application:
170175

171176
```tsx
172177
import React from "react";
173178
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
174179
import ReactDOM from "react-dom/client";
175180
import App from "./App";
176181

177-
// Create a client
182+
// Import the SDK core class and provider from your generated SDK
183+
import { YourSDKCore } from "your-sdk-package";
184+
import { YourSDKProvider } from "your-sdk-package/react-query";
185+
186+
// Create a TanStack Query client
178187
const queryClient = new QueryClient();
179188

189+
// Create an instance of your SDK with any required configuration
190+
const sdkClient = new YourSDKCore({
191+
// Add your SDK configuration here, such as:
192+
// apiKey: process.env.API_KEY,
193+
});
194+
195+
// Optionally disable TanStack Query's built-in retries since the SDK handles retries
196+
queryClient.setQueryDefaults(["your-sdk-package"], { retry: false });
197+
queryClient.setMutationDefaults(["your-sdk-package"], { retry: false });
198+
180199
ReactDOM.createRoot(document.getElementById("root")!).render(
181200
<React.StrictMode>
182201
<QueryClientProvider client={queryClient}>
183-
<App />
202+
<YourSDKProvider client={sdkClient}>
203+
<App />
204+
</YourSDKProvider>
184205
</QueryClientProvider>
185206
</React.StrictMode>,
186207
);
187208
```
188209

210+
The SDK provider makes the API client available to all hooks in your component tree. Replace `your-sdk-package`, `YourSDKCore`, and `YourSDKProvider` with the actual names from your generated SDK.
211+
189212
## Basic usage
190213

191214
You can use the generated Hooks in your components as follows:

0 commit comments

Comments
 (0)