@squidcloud/react
Interfaces
Type Aliases
DocOptions
Ƭ DocOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
enabled? | boolean | Determines whether to query the document data automatically. Defaults to true . When set to false , executing the query will be delayed until enabled is set to true . |
subscribe? | boolean | Whether to subscribe to document updates. Defaults to true . |
DocType
Ƭ DocType<T
>: Object
Represents the state and data of a document request within the Squid framework.
Type parameters
Name | Type | Description |
---|---|---|
T | extends DocumentData | The type extending DocumentData which defines the expected shape of the document's data. |
Type declaration
Name | Type | Description |
---|---|---|
data | T | undefined | The document's data if available; undefined if the data is not yet fetched or if no data exists. |
error | any | Any error that may have occurred during the document request. |
loading | boolean | Indicates whether the document request is in progress. |
DocsType
Ƭ DocsType<T
>: Object
Represents the state and collection of document data returned from a query within the Squid framework.
Type parameters
Name | Type | Description |
---|---|---|
T | extends DocumentData | The type extending DocumentData which defines the expected shape of each document's data in the array. |
Type declaration
Name | Type | Description |
---|---|---|
data | (T | undefined )[] | An array of document data, where each item is either the document's data or undefined if the data is not yet fetched or if no data exists for that item. |
error | any | Any error that may have occurred during the document data collection request. |
loading | boolean | Indicates whether the document data collection request is in progress. |
ObservableOptions
Ƭ ObservableOptions<T
>: Object
Type parameters
Name |
---|
T |
Type declaration
Name | Type | Description |
---|---|---|
enabled? | boolean | Determines whether to execute the observable automatically. Defaults to true . When set to false , executing the observable will be delayed until enabled is set to true . |
initialData? | T | The initial data to be used for the data before the observable emits. Defaults to null . |
ObservableType
Ƭ ObservableType<T
>: Object
Type representing the state and data of an observable request.
Type parameters
Name | Description |
---|---|
T | The type of data the observable emits. |
Type declaration
Name | Type | Description |
---|---|---|
complete | boolean | Indicates whether the observable has completed its stream. |
data | T | The latest data emitted by the observable. |
error | any | Any error that may have occurred during the observable request. |
loading | boolean | Indicates whether the observable request is in progress. |
PaginationType
Ƭ PaginationType<T
>: Object
Type representing the state and data of a paginated query.
Type parameters
Name | Description |
---|---|
T | The type of the data items within the paginated data set. |
Type declaration
Name | Type | Description |
---|---|---|
data | T [] | An array of data items for the current page. |
hasNext | boolean | Indicates if there is a next page available. |
hasPrev | boolean | Indicates if there is a previous page available. |
loading | boolean | Indicates whether the pagination data is currently being loaded. |
next | () => void | Function to navigate to the next page. |
prev | () => void | Function to navigate to the previous page. |
PromiseOptions
Ƭ PromiseOptions<T
>: Object
Type parameters
Name |
---|
T |
Type declaration
Name | Type | Description |
---|---|---|
enabled? | boolean | Determines whether to execute the promise automatically. Defaults to true . When set to false , executing the promise will be delayed until enabled is set to true . |
initialData? | T | The initial state for the data before the promise resolves. Defaults to null . |
PromiseType
Ƭ PromiseType<T
>: Object
Type representing the state of an asynchronous operation provided by a promise.
Type parameters
Name | Type | Description |
---|---|---|
T | any | The type of the data that the promise will resolve with. |
Type declaration
Name | Type | Description |
---|---|---|
data | T | The data resolved by the promise, if any. |
error | any | Any error that may have been thrown during the promise resolution. |
loading | boolean | Indicates whether the promise is currently being resolved. |
QueryOptions
Ƭ QueryOptions<T
>: Object
Type parameters
Name |
---|
T |
Type declaration
Name | Type | Description |
---|---|---|
enabled? | boolean | Determines whether the query runs automatically. Defaults to true . When set to false , executing the query will be delayed until enabled is set to true . |
initialData? | T [] | An optional array of initial data items to be used before the query resolves for the first time. If a parent query is active, this defaults to data currently available the client. Otherwise, the default is an empty array. |
subscribe? | boolean | Determines whether to continuously subscribe to query updates. If false , a single snapshot will be fetched. Defaults to true |
QueryType
Ƭ QueryType<T
>: Object
Type representing the state of a Squid query operation.
Type parameters
Name | Description |
---|---|
T | The type of the data items that the query will return. |
Type declaration
Name | Type | Description |
---|---|---|
data | T [] | The data items returned by the query. |
error | any | Any error that may have occurred during the query execution. |
loading | boolean | Indicates whether the query is currently being resolved. |
QueueOptions
Ƭ QueueOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
enabled? | boolean | Determines whether the queue beings consuming automatically. Defaults to true . When set to false , consuming messages will be paused until enabled is set to true . |
QueueType
Ƭ QueueType<T
>: Object
Type representing the state of a Squid queue.
Type parameters
Name | Description |
---|---|
T | The type of the data that the queue will return. |
Type declaration
Name | Type | Description |
---|---|---|
data | T | null | The most recent message consumed by the queue. |
error | any | Any error that may have occurred during while consuming messages. |
produce | (messages : T []) => Promise <void > | A wrapper around queue.produce. |
SquidContextType
Ƭ SquidContextType: Object
Type representing the context for the Squid library.
Type declaration
Name | Type |
---|---|
squid | Squid | null |
WithQueryOptions
Ƭ WithQueryOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
subscribe? | boolean | If true, the Component will subscribe to the query snapshots. Defaults to true . |
Variables
SquidContext
• Const
SquidContext: Context
<SquidContextType
>
React Context for Squid. Provides a way to pass the Squid instance down the component tree without having to pass the prop down manually at every level. It is created with a default value of null for the squid instance.
Functions
SquidContextProvider
▸ SquidContextProvider(props
, context?
): ReactNode
React Component to provide Squid instance to all children in the component tree.
Parameters
Name | Type |
---|---|
props | SquidContextProps |
context? | any |
Returns
ReactNode
A React context provider with the Squid instance.
useAiChatbot
▸ useAiChatbot(integrationId
, profileId
): AiHookResponse
Parameters
Name | Type |
---|---|
integrationId | string |
profileId | string |
Returns
AiHookResponse
useAiQuery
▸ useAiQuery(integrationId
): AiHookResponse
Custom hook for making AI queries with a given database integration ID.
Parameters
Name | Type | Description |
---|---|---|
integrationId | string | The unique identifier for the database integration instance. |
Returns
AiHookResponse
An object containing methods and state for AI chat interactions.
Deprecated
- Please import from
useAiAgent
useAiQueryMulti
▸ useAiQueryMulti(integrationIds
): AiHookResponse
Custom hook for making AI queries with multiple database integration IDs.
Parameters
Name | Type | Description |
---|---|---|
integrationIds | string [] | The unique identifiers for the database integrations. |
Returns
AiHookResponse
An object containing methods and state for AI chat interactions.
Deprecated
- Please import from
useAiAgent
useCollection
▸ useCollection<T
>(collectionName
, integrationId?
): CollectionReference
<T
>
Hook to get a Squid collection reference.
Type parameters
Name | Type | Description |
---|---|---|
T | extends DocumentData | extends DocumentData |
Parameters
Name | Type | Description |
---|---|---|
collectionName | string | Name of the collection. |
integrationId? | string | Optional integration id. |
Returns
CollectionReference
<T
>
Reference to the collection.
Throws
Will throw an error if used outside a SquidContext.Provider.
useDoc
▸ useDoc<T
>(doc
, options?
): DocType
<T
>
Hook to get a Squid document data, loading state, and errors.
Type parameters
Name | Type | Description |
---|---|---|
T | extends DocumentData | extends DocumentData |
Parameters
Name | Type | Description |
---|---|---|
doc | DocumentReference <T > | Squid document reference. |
options | DocOptions | Options to control the behavior of the document query. |
Returns
DocType
<T
>
The document data, loading state, and errors.
useDocs
▸ useDocs<T
>(docs
, options?
): DocsType
<T
>
Hook to get multiple Squid documents data, loading state, and errors.
Type parameters
Name | Type | Description |
---|---|---|
T | extends DocumentData | extends DocumentData |
Parameters
Name | Type | Description |
---|---|---|
docs | DocumentReference <T >[] | Array of Squid document references. |
options? | DocOptions | Options to control the behavior of the of the document queries. |
Returns
DocsType
<T
>
The documents data, loading state, and errors.
useObservable
▸ useObservable<T
>(observable
, options
, deps?
): ObservableType
<T
>
Hook that subscribes to an RXJS Observable and keeps track of its loading state, data, errors, and completion state. This hook handles the subscription and unsubscription to the observable provided.
Type parameters
Name | Description |
---|---|
T | The type of data the observable emits. |
Parameters
Name | Type | Description |
---|---|---|
observable | () => Observable <T > | A function that returns the observable to subscribe to. |
options | ObservableOptions <T > & { initialData : T } | Options to control the behavior of the observable. |
deps? | readonly unknown [] | Optional array of dependencies that, when changed, will re-subscribe to the provided observable function. |
Returns
An object containing the observable's current loading state, the latest data emitted, any errors encountered, and completion state.
▸ useObservable<T
>(observable
, options?
, deps?
): ObservableType
<T
| null
>
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
observable | () => Observable <T > |
options? | ObservableOptions <T > |
deps? | readonly unknown [] |
Returns
ObservableType
<T
| null
>
usePagination
▸ usePagination<T
>(query
, options
, deps?
): PaginationType
<T
>
Hook that provides a simple interface for paginating data from a Squid query. It returns the current pagination state including the data for the current page, loading status, and functions to navigate to the next and previous pages.
Type parameters
Name | Description |
---|---|
T | A type extending SnapshotEmitter , typically a Squid query. |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
query | Pick <SnapshotEmitter <T >, "paginate" > | undefined | The Squid query. |
options | PaginationOptions | undefined | Pagination options to control the behavior of the pagination. |
deps | readonly unknown [] | [] | An array of dependencies that, when changed, will reset the pagination and re-run the query. |
Returns
An object containing the current state of the pagination, including the data for the current page, loading status, and functions to navigate between pages.
usePromise
▸ usePromise<T
>(promiseFn
, options
, deps?
): PromiseType
<T
>
Hook that provides state management for asynchronous operations, representing the loading state, the resolved data, and any error that may occur. It is particularly useful for handling promises, such as data fetching operations.
Type parameters
Name | Description |
---|---|
T | The expected type of the data to be resolved by the promise. |
Parameters
Name | Type | Description |
---|---|---|
promiseFn | () => Promise <T > | A function that returns a promise, which resolves to the data of type T . |
options | PromiseOptions <T > & { initialData : T } | Options to control the behavior of the promise. |
deps? | readonly unknown [] | An array of dependencies that, when changed, will trigger the promise function to be called again. |
Returns
PromiseType
<T
>
An object containing the current state of the asynchronous operation: the loading status, the resolved data, and any error.
▸ usePromise<T
>(promiseFn
, options?
, deps?
): PromiseType
<T
| null
>
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
promiseFn | () => Promise <T > |
options? | PromiseOptions <T > |
deps? | readonly unknown [] |
Returns
PromiseType
<T
| null
>
useQuery
▸ useQuery<T
>(query
, options?
, deps?
): QueryType
<T
>
Hook that provides state management for Squid queries, giving access to the data items, the loading status, and any errors encountered during the query execution. It can subscribe to continuous data updates or fetch a single snapshot depending on the subscription parameter.
Type parameters
Name | Description |
---|---|
T | The expected type of the individual data items returned by the query. |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
query | SnapshotEmitter <T > | undefined | The Squid query. |
options | QueryOptions <T > | {} | Options to control the behavior of the query. |
deps | readonly unknown [] | [] | An array of dependencies that, when changed, will cause the hook to resubscribe to the query updates. |
Returns
QueryType
<T
>
An object containing the current state of the query operation: the loading status, the array of data items, and any error.
useQueue
▸ useQueue<T
>(queue
, options?
, deps?
): QueueType
<T
>
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value |
---|---|---|
queue | QueueManager <T > | undefined |
options | QueueOptions | {} |
deps | readonly unknown [] | [] |
Returns
QueueType
<T
>
useSquid
▸ useSquid(): Squid
React Hook to get the Squid instance from the SquidContext.
Returns
Squid
The Squid instance from the context.
Throws
Will throw an error if used outside a SquidContext.Provider.
withServerQuery
▸ withServerQuery<C
, T
>(Component
, query
, options?
): FC
<Omit
<ComponentProps
<C
>, "data"
>>
Higher Order Component (HOC) to wrap a component with a server query.
Type parameters
Name | Type | Description |
---|---|---|
C | extends ComponentType <any > | The type of the React component. |
T | T | The type of the data in the query. |
Parameters
Name | Type | Description |
---|---|---|
Component | C | The component to wrap. |
query | SnapshotEmitter <T > | The query object. |
options? | WithQueryOptions | Options to control the behavior of the HOC. |
Returns
FC
<Omit
<ComponentProps
<C
>, "data"
>>
A new component that wraps the given component with the server query.