Hook Output Type Reference

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

1function Component() {
2 const hook = useTestAws({
3 stream: true, // optional, defaults to true
4 })
5
6 return (
7 <div>
8 {hook.error && <div>Error: {hook.error.message}</div>}
9 <button onClick={() => hook.mutate("test")} disabled={hook.isLoading}>
10 Submit
11 </button>
12 </div>
13 )
14}

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.

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.

Built with