This hook is experimental and may change in future versions.
Parameters
string
required
The API endpoint. It should stream JSON that matches the schema as chunked text.
FlexibleSchema
required
A schema that defines the shape of the complete object.
string
An unique identifier. If not provided, a random one will be generated.
When provided, the
useObject hook with the same id will have shared states across components.DeepPartial<RESULT>
An optional value for the initial object.
FetchFunction
Custom fetch implementation. You can use it as a middleware to intercept requests,
or to provide a custom fetch implementation for e.g. testing.
(event: { object: RESULT | undefined; error: Error | undefined }) => void
Callback function to be called when the stream has finished.
The generated object (typed according to the schema) is passed as an argument.
Can be undefined if the final object does not match the schema.
(error: Error) => void
Callback function to be called when an error is encountered.
Record<string, string> | Headers | (() => Record<string, string> | Headers | Promise<Record<string, string> | Headers>)
Additional HTTP headers to be included in the request.
Can be a static object, a function that returns headers, or an async function for dynamic auth tokens.
RequestCredentials
The credentials mode to be used for the fetch request.
Possible values are:
'omit', 'same-origin', 'include'.
Defaults to 'same-origin'.Returns
(input: INPUT) => void
Calls the API with the provided input as JSON body.
DeepPartial<RESULT> | undefined
The current value for the generated object. Updated as the API streams JSON chunks.
Error | undefined
The error object of the API request if any.
boolean
Flag that indicates whether an API request is in progress.
() => void
Abort the current request immediately, keep the current partial object if any.
() => void
Clear the object state.