> 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 Input Type Reference

> Technical reference for the BAML React hook input type

The `HookInput` type defines the configuration options for BAML React hooks.

**`Example Usage`**

```typescript title="Example Usage"
function Component() {
  const hook = useTestAws({
    stream: true, // optional, defaults to true
    onStreamData: (text) => console.log("Streaming:", text),
    onFinalData: (text) => console.log("Complete:", text),
    onData: (text) => console.log("Any update:", text),
    onError: (error) => console.error("Error:", error)
  })

  return <div>{hook.data}</div>
}
```

**`Example Types`**

```typescript title="Example Types"
// Streaming configuration
const streamingInput: HookInput<'TestAws', { stream: true }> = {
  stream: true,
  onStreamData: (text) => console.log("Streaming:", text),
  onFinalData: (text) => console.log("Final:", text),
  onData: (text) => console.log("Any update:", text),
  onError: (error) => console.error(error),
}

// Non-streaming configuration
const nonStreamingInput: HookInput<'TestAws', { stream: false }> = {
  stream: false,
  onFinalData: (text) => console.log("Result:", text),
  onData: (text) => console.log("Result:", text),
  onError: (error) => console.error(error)
}
```

**`Type Definition`**

```typescript title="Type Definition"
type HookInput<FunctionName, Options extends { stream?: boolean } = { stream?: true }> = {
  stream?: Options['stream']
  onStreamData?: Options['stream'] extends false ? never : (response?: StreamDataType<FunctionName>) => void
  onFinalData?: (response?: FinalDataType<FunctionName>) => void
  onData?: (response?: StreamDataType<FunctionName> | FinalDataType<FunctionName>) => void
  onError?: (error: BamlErrors) => void
}
```

## Type Parameters

**`FunctionName`** `generic`

The name of the BAML function being called. Used to infer the correct types for responses.

---

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

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

---

## Properties

**`stream`** `boolean | undefined`

Flag to enable or disable streaming mode. When true, enables streaming responses.

---

**`onStreamData`** `(response?: StreamDataType<FunctionName>) => void`

Callback function for streaming responses. Only available when `Options['stream']` is true.

---

**`onFinalData`** `(response?: FinalDataType<FunctionName>) => void`

Callback function for the final response.

---

**`onData`** `(response?: StreamDataType<FunctionName> | FinalDataType<FunctionName>) => void`

Unified callback function that receives both streaming and final responses. For non-streaming hooks, only receives final responses.

---

**`onError`** `(error: BamlErrors) => void`

Callback function for error handling. See [Error Types](../errors/overview).

---