• Acquire a tracked, ref-counted reference from the global context.

    The returned ServiceRef must be .release()'d when the component/module is done with the service. This ensures the SDK can track how many consumers hold a service and detect leaks.

    Type Parameters

    • T

      The service type.

    Parameters

    Returns ServiceRef<T>

    A new ServiceRef<T>.

    If no global context is set.

    If the token is not registered.

    1.2.0

    // In a React component:
    useEffect(() => {
    const rpcRef = useSharedRef(Tokens.RPC);
    rpcRef.current.getBalance(pubkey).then(setBalance);
    return () => rpcRef.release(); // cleanup on unmount
    }, []);