> Version notice: This site documents BAML v0, the legacy DSL. BAML v1 is a separate, fully featured programming language in public beta. If the user intends to use BAML v1, ignore this site's content and use the BAML v1 documentation instead. If the intended version is unclear, clarify it before using this page.
> For clean Markdown of any page, append .md to the page URL. For the complete documentation index, see https://docs.boundaryml.com/llms.txt. For MCP access, connect to https://docs.boundaryml.com/_mcp/server.

# Hook Output Type Reference

> Technical reference for the BAML React hook output type

The `HookOutput` type defines the return type for BAML React hooks.

**`Example Usage`**

```typescript title="Example Usage"
function Component() {
  const hook = useTestAws({
    stream: true, // optional, defaults to true
  })

  return (
    <div>
      {hook.error && <div>Error: {hook.error.message}</div>}
      <button onClick={() => hook.mutate("test")} disabled={hook.isLoading}>
        Submit
      </button>
    </div>
  )
}
```

**`Example Types`**

```typescript title="Example Types"
// Streaming configuration
const streamingResult: HookOutput<'TestAws', { stream: true }> = {
  data: "Any response",
  finalData: "Final response",
  streamData: "Streaming response...",
  error: undefined,
  isError: false,
  isLoading: true,
  isSuccess: false,
  isStreaming: true,
  isPending: false,
  status: 'streaming',
  mutate: async () => new ReadableStream(),
  reset: () => void
}

// Non-streaming configuration
const nonStreamingResult: HookOutput<'TestAws', { stream: false }> = {
  data: "Final response",
  finalData: "Final response",
  error: undefined,
  isError: false,
  isLoading: false,
  isSuccess: true,
  isPending: false,
  status: 'success',
  mutate: async () => "Final response",
  reset: () => void
}
```

**`Type Definition`**

```typescript title="Type Definition"
type HookOutput<FunctionName, Options extends { stream?: boolean } = { stream?: true }> = {
  data?: Options['stream'] extends false ? FinalDataType<FunctionName> : FinalDataType<FunctionName> | StreamDataType<FunctionName>
  finalData?: FinalDataType<FunctionName>
  streamData?: Options['stream'] extends false ? never : StreamDataType<FunctionName>
  error?: BamlErrors
  isError: boolean
  isLoading: boolean
  isPending: boolean
  isSuccess: boolean
  isStreaming: Options['stream'] extends false ? never : boolean
  status: HookStatus<Options>
  mutate: (...args: Parameters<ServerAction>) => Options['stream'] extends false
    ? Promise<FinalDataType<FunctionName>>
    : Promise<ReadableStream<Uint8Array>>
  reset: () => void
}

type HookStatus<Options extends { stream?: boolean }> = Options['stream'] extends false
  ? 'idle' | 'pending' | 'success' | 'error'
  : 'idle' | 'pending' | 'streaming' | 'success' | 'error'
```

## Type Parameters

**`FunctionName`** `generic`

The name of the BAML function being called. Used to infer input and output types.

---

**`Options`** `{ stream?: boolean }`

Configuration object that determines streaming behavior. Defaults to `{ stream?: true }`.

---

## Properties

**`data`** `FinalDataType<FunctionName> | StreamDataType<FunctionName> | undefined`

The current response data. For streaming hooks, this contains either the latest streaming response or the final response. For non-streaming hooks, this only contains the final response.

---

**`finalData`** `FinalDataType<FunctionName> | undefined`

The final response data. Only set when the request completes successfully.

---

**`streamData`** `StreamDataType<FunctionName> | undefined`

The latest streaming response. Only available when `Options['stream']` is true.

---

**`error`** `BamlErrors | undefined`

Any error that occurred during the request. See [Error Types](../errors/overview).

---

**`isError`** `boolean`

True if the request resulted in an error.

---

**`isLoading`** `boolean`

True if the request is in progress (either pending or streaming).

---

**`isPending`** `boolean`

True if the request is pending (not yet streaming or completed).

---

**`isSuccess`** `boolean`

True if the request completed successfully.

---

**`isStreaming`** `boolean`

True if the request is currently streaming data. Only available when `Options['stream']` is true.

---

**`status`** `HookStatus<Options>`

The current status of the request. For streaming hooks: 'idle' | 'pending' | 'streaming' | 'success' | 'error'. For non-streaming hooks: 'idle' | 'pending' | 'success' | 'error'.

---

**`mutate`** `(...args: Parameters<ServerAction>) => Promise<OutputType>`

Function to trigger the BAML action. Returns a ReadableStream for streaming hooks, or a Promise of the final response for non-streaming hooks.

---

**`reset`** `() => void`

Function to reset the hook state back to its initial values.

---