# useClientTransport Read the `ClientTransport` exposed by the nearest [`TransportProvider`](https://ably.com/docs/ai-transport/api/react/providers.md#TransportProvider). The hook is a thin context reader; it does not create or own transport state. This hook must be used within a [`TransportProvider`](https://ably.com/docs/ai-transport/api/react/providers.md#TransportProvider) or a [`ChatTransportProvider`](https://ably.com/docs/ai-transport/api/react/providers.md#ChatTransportProvider). #### React ``` import { useClientTransport } from '@ably/ai-transport/react'; function Chat() { const { transport, transportError } = useClientTransport(); if (transportError) return ; // Use transport.view, transport.cancel(), etc. } ``` ## Parameters | Prop | Required | Description | Type | | --- | --- | --- | --- | | channelName | Optional | The `channelName` of the `TransportProvider` to read from. Omit to use the nearest provider in the tree. | String | | skip | Optional | When `true`, returns a stub transport that throws on any access. Useful when a condition (auth, feature flag) is not yet resolved. | Boolean | | onError | Optional | Called whenever the resolved transport emits a non-fatal error. The subscription is established once the transport resolves and removed on unmount or when the transport changes. | `(error: Ably.ErrorInfo) => void` |
## Returns `ClientTransportHandle` | Property | Description | Type | | --- | --- | --- | | transport | The resolved transport. A throwing stub when `skip` is `true`, when no matching provider is found, or when transport construction failed. Check `transportError` before use. | `ClientTransport` | | transportError | Set when no matching provider is found or transport construction failed and `skip` is `false`. `undefined` when the transport resolved successfully or `skip` is `true`. | `Ably.ErrorInfo` or Undefined |
Check `transportError` before using `transport` to avoid throws from the stub. See [`ClientTransport`](https://ably.com/docs/ai-transport/api/javascript/client-transport.md) for the full surface the returned transport exposes. ## Example ### React ``` import { useClientTransport, useView } from '@ably/ai-transport/react'; function Chat() { const { transport, transportError } = useClientTransport({ onError: (error) => console.error(`Transport error ${error.code}:`, error.message), }); const { messages } = useView({ limit: 30 }); if (transportError) return ; return (
{messages.map((m) => )}
); } ```
## Related Topics - [Providers](https://ably.com/docs/ai-transport/api/react/providers.md): TransportProvider and ChatTransportProvider for the AI Transport React integration. - [useView](https://ably.com/docs/ai-transport/api/react/use-view.md): Subscribe to a paginated, branch-aware view of the AI Transport conversation tree from React. - [useCreateView](https://ably.com/docs/ai-transport/api/react/use-create-view.md): Create an independent View over the AI Transport conversation tree from React, with its own branch selections and pagination. - [useTree](https://ably.com/docs/ai-transport/api/react/use-tree.md): Stable structural query callbacks for the AI Transport conversation tree from React. - [useActiveTurns](https://ably.com/docs/ai-transport/api/react/use-active-turns.md): Subscribe to active turns on the AI Transport channel from React. - [useAblyMessages](https://ably.com/docs/ai-transport/api/react/use-ably-messages.md): Subscribe to raw Ably InboundMessages on the AI Transport channel from React. - [useChatTransport](https://ably.com/docs/ai-transport/api/react/use-chat-transport.md): Read a ChatTransport and its underlying ClientTransport from the nearest ChatTransportProvider in AI Transport. - [useMessageSync](https://ably.com/docs/ai-transport/api/react/use-message-sync.md): Wire AI Transport message updates into Vercel useChat's message state from React. ## Documentation Index To discover additional Ably documentation: 1. Fetch [llms.txt](https://ably.com/llms.txt) for the canonical list of available pages. 2. Identify relevant URLs from that index. 3. Fetch target pages as needed. Avoid using assumed or outdated documentation paths.