effect-rpc
    Preparing search index...

    Function useRPCRequest

    • Creates a function to perform an RPC request using the provided RPC group and request name.

      This hook returns a function that, when called with the appropriate payload, constructs an Effect program that:

      • Instantiates an RPC client for the given group.
      • Invokes the specified request with the provided payload.
      • Logs the response.
      • Returns the response as the result of the Effect.

      Type Parameters

      • T extends RpcGroup<any>

        The type of the RPC group, extending RpcGroup.RpcGroup<any>.

      • K extends string | number | symbol

        The key of the request within the inferred client from the RPC group.

      Parameters

      • rpcGroup: T

        The RPC group definition containing available RPC methods.

      • requestName: K

        The name of the request method to invoke within the RPC group.

      Returns (payload: Parameters<InferClient<T>[K]>[0]) => ReturnType<InferClient<T>[K]>

      A function that takes the request payload and returns an Effect program representing the RPC call and its response.

      const getUser = useRPCRequest(userRpcGroup, "getUser");
      const program = getUser({ id: "123" });
      // program is an Effect that, when run, will perform the RPC call and return the user data.