Skip to main content

@squidcloud/react

Interfaces

Type Aliases

DocOptions

Ƭ DocOptions: Object

Type declaration

NameTypeDescription
enabled?booleanDetermines 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?booleanWhether 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

NameTypeDescription
Textends DocumentDataThe type extending DocumentData which defines the expected shape of the document's data.

Type declaration

NameTypeDescription
dataT | undefinedThe document's data if available; undefined if the data is not yet fetched or if no data exists.
erroranyAny error that may have occurred during the document request.
loadingbooleanIndicates 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

NameTypeDescription
Textends DocumentDataThe type extending DocumentData which defines the expected shape of each document's data in the array.

Type declaration

NameTypeDescription
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.
erroranyAny error that may have occurred during the document data collection request.
loadingbooleanIndicates whether the document data collection request is in progress.

ObservableOptions

Ƭ ObservableOptions<T>: Object

Type parameters

Name
T

Type declaration

NameTypeDescription
enabled?booleanDetermines 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?TThe 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

NameDescription
TThe type of data the observable emits.

Type declaration

NameTypeDescription
completebooleanIndicates whether the observable has completed its stream.
dataTThe latest data emitted by the observable.
erroranyAny error that may have occurred during the observable request.
loadingbooleanIndicates whether the observable request is in progress.

PaginationType

Ƭ PaginationType<T>: Object

Type representing the state and data of a paginated query.

Type parameters

NameDescription
TThe type of the data items within the paginated data set.

Type declaration

NameTypeDescription
dataT[]An array of data items for the current page.
hasNextbooleanIndicates if there is a next page available.
hasPrevbooleanIndicates if there is a previous page available.
loadingbooleanIndicates whether the pagination data is currently being loaded.
next() => voidFunction to navigate to the next page.
prev() => voidFunction to navigate to the previous page.

PromiseOptions

Ƭ PromiseOptions<T>: Object

Type parameters

Name
T

Type declaration

NameTypeDescription
enabled?booleanDetermines 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?TThe 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

NameTypeDescription
TanyThe type of the data that the promise will resolve with.

Type declaration

NameTypeDescription
dataTThe data resolved by the promise, if any.
erroranyAny error that may have been thrown during the promise resolution.
loadingbooleanIndicates whether the promise is currently being resolved.

QueryOptions

Ƭ QueryOptions<T>: Object

Type parameters

Name
T

Type declaration

NameTypeDescription
enabled?booleanDetermines 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?booleanDetermines 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

NameDescription
TThe type of the data items that the query will return.

Type declaration

NameTypeDescription
dataT[]The data items returned by the query.
erroranyAny error that may have occurred during the query execution.
loadingbooleanIndicates whether the query is currently being resolved.

QueueOptions

Ƭ QueueOptions: Object

Type declaration

NameTypeDescription
enabled?booleanDetermines 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

NameDescription
TThe type of the data that the queue will return.

Type declaration

NameTypeDescription
dataT | nullThe most recent message consumed by the queue.
erroranyAny 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

NameType
squidSquid | null

WithQueryOptions

Ƭ WithQueryOptions: Object

Type declaration

NameTypeDescription
subscribe?booleanIf 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

NameType
propsSquidContextProps
context?any

Returns

ReactNode

A React context provider with the Squid instance.


useAiChatbot

useAiChatbot(integrationId, profileId): AiHookResponse

Parameters

NameType
integrationIdstring
profileIdstring

Returns

AiHookResponse


useAiQuery

useAiQuery(integrationId): AiHookResponse

Custom hook for making AI queries with a given database integration ID.

Parameters

NameTypeDescription
integrationIdstringThe 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

NameTypeDescription
integrationIdsstring[]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

NameTypeDescription
Textends DocumentDataextends DocumentData

Parameters

NameTypeDescription
collectionNamestringName of the collection.
integrationId?stringOptional 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

NameTypeDescription
Textends DocumentDataextends DocumentData

Parameters

NameTypeDescription
docDocumentReference<T>Squid document reference.
optionsDocOptionsOptions 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

NameTypeDescription
Textends DocumentDataextends DocumentData

Parameters

NameTypeDescription
docsDocumentReference<T>[]Array of Squid document references.
options?DocOptionsOptions 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

NameDescription
TThe type of data the observable emits.

Parameters

NameTypeDescription
observable() => Observable<T>A function that returns the observable to subscribe to.
optionsObservableOptions<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

ObservableType<T>

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

NameType
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

NameDescription
TA type extending SnapshotEmitter, typically a Squid query.

Parameters

NameTypeDefault valueDescription
queryPick<SnapshotEmitter<T>, "paginate">undefinedThe Squid query.
optionsPaginationOptionsundefinedPagination options to control the behavior of the pagination.
depsreadonly unknown[][]An array of dependencies that, when changed, will reset the pagination and re-run the query.

Returns

PaginationType<T>

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

NameDescription
TThe expected type of the data to be resolved by the promise.

Parameters

NameTypeDescription
promiseFn() => Promise<T>A function that returns a promise, which resolves to the data of type T.
optionsPromiseOptions<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

NameType
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

NameDescription
TThe expected type of the individual data items returned by the query.

Parameters

NameTypeDefault valueDescription
querySnapshotEmitter<T>undefinedThe Squid query.
optionsQueryOptions<T>{}Options to control the behavior of the query.
depsreadonly 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

NameTypeDefault value
queueQueueManager<T>undefined
optionsQueueOptions{}
depsreadonly 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

NameTypeDescription
Cextends ComponentType<any>The type of the React component.
TTThe type of the data in the query.

Parameters

NameTypeDescription
ComponentCThe component to wrap.
querySnapshotEmitter<T>The query object.
options?WithQueryOptionsOptions 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.