Valora
API Reference@valora-ai/reactindexFunctions

useRpc

function useRpc<S>(
   _session, 
   _methodName, 
handler): UseRpcReturn<S, S>;

Defined in: packages/react/src/hooks/room/useRpc.ts:42

Note. This feature is under active development and may change based on developer feedback and real-world usage. Hook for declarative RPC method registration and outbound RPC calls. Registers a handler for an incoming RPC

Type Parameters

Type ParameterDefault type
Sunknown

Parameters

ParameterType
_sessionunknown
_methodNamestring
handlerRpcHandler<S, S>

Returns

UseRpcReturn<S, S>

Example

// Basic — register an RPC handler on a session.
const { performRpc } = useRpc(async (payload: { highAccuracy: boolean }) => getPosition(payload), "getUserLocation", session);

// Advanced — call an agent method from a room action.
function LocationButton({ session }: { session: UseSessionReturn }) {
  const { performRpc } = useRpc(
    async (payload: { highAccuracy: boolean }) => getPosition(payload),
    "getUserLocation",
    session,
  );

  return <button onClick={() => performRpc({ destinationIdentity: "myAgent", payload: { highAccuracy: true } })}>Share location</button>;
}

On this page

Valora is local-first

No API key, no server — everything in this doc runs on-device.

Star on GitHub