useClientCapability

function useClientCapability<TClient>(
    __namedParameters,
): Client<TClient>;

Reads the client from the nearest ClientProvider and asserts at mount that the requested capability is installed, narrowing the return type via the generic. Throws a SolanaError with code SOLANA_ERROR__REACT__MISSING_CAPABILITY when the capability is absent — including the calling hookName and a providerHint so users can fix the mistake without cross-referencing docs.

Use this from the implementation of plugin-specific hooks. Apps that need ad-hoc access without a runtime check can reach for useClient directly and supply their own type narrowing.

Type Parameters

Type ParameterDescription
TClient extends objectThe narrowed client shape returned once the capability assertion passes. Always pass this generic — the hook can't infer it from a string.

Parameters

ParameterType
__namedParametersUseClientCapabilityConfig

Returns

Client<TClient>

Example

import { ClientWithRpc, GetEpochInfoApi } from '@solana/kit';
import { useClientCapability } from '@solana/react';
 
function useRpc() {
    return useClientCapability<ClientWithRpc<GetEpochInfoApi>>({
        capability: 'rpc',
        hookName: 'useRpc',
        providerHint: 'Install `solanaRpc()` on the client.',
    });
}

See

On this page