Generated Hooks Reference
BAML automatically generates a type-safe React hook for each BAML function. Each hook follows the naming pattern use{FunctionName}
and supports both streaming and non-streaming modes.
HookInput
The hook accepts an optional configuration object. See Hook Input for complete details.
Enable streaming mode for real-time updates. Defaults to true.
Callback for streaming updates. Only available when streaming is enabled.
Callback when the request completes.
Unified callback for both streaming and final responses.
Callback when an error occurs. See Error Types.
HookOutput
The hook returns an object with the following properties. See Hook Output for complete details.
The current response data. Contains either streaming or final data depending on the request state.
The final response data. Only available when the request completes.
Latest streaming update. Only available in streaming mode.
Error information if the request fails. See Error Types.
True while the request is in progress (either pending or streaming).
True if the request is pending (not yet streaming or completed).
True if the request is currently streaming data. Only available in streaming mode.
True if the request completed successfully.
True if the request failed.
Current state of the request. For streaming hooks: ‘idle’ | ‘pending’ | ‘streaming’ | ‘success’ | ‘error’. For non-streaming hooks: ‘idle’ | ‘pending’ | ‘success’ | ‘error’.
Function to execute the BAML function. Returns a ReadableStream for streaming hooks, or a Promise of the final response for non-streaming hooks.
Function to reset the hook state back to its initial values.