Hook Input Type Reference

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

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>
}

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.