Hook Input Type Reference

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

1function Component() {
2 const hook = useTestAws({
3 stream: true, // optional, defaults to true
4 onStreamData: (text) => console.log("Streaming:", text),
5 onFinalData: (text) => console.log("Complete:", text),
6 onData: (text) => console.log("Any update:", text),
7 onError: (error) => console.error("Error:", error)
8 })
9
10 return <div>{hook.data}</div>
11}

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.

Built with