number, an unpaged list an array and a single record the record itself, with no one-field wrapper such as { count } or { data }. Answers that carry several fields (a status check, for example) stay records, paginated hooks keep their paging, and fetch-or-create hooks (useFetchOrCreateEntityByForeignId, useCreateDirectConversation) resolve to { <record>, created }, where created is true when the call created the record. Actions that are safe to repeat, such as adding a chat member, blocking a user or joining a space, are not fetch-or-create: they give the same response whether or not this call made the change.
For higher-level integration guidance, see the SDK Reference.
Hook conventions
Every hook follows the same rules for its flags, errors and functions.- Flags. A fact about the data starts with
is,hasorcan(isMember,isFollowing,hasMore,canPost). Something in progress right now is the bare “-ing” word:loading,uploading,updating,switching,removing,streaming. - Errors. Every
errora hook returns is aSublayErrorornull, and every function a hook returns rejects with aSublayErrorwhen it fails. One field is not anerror: the comment section’screateErroris a plainCommentCreateErrorrecord (code,message,status,parentCommentId), because it describes a failed comment create together with the reply it was for, and is whatcommentCreateFailedCallbackreceives. - Action hooks return one function that takes one object:
const createEntity = useCreateEntity(); createEntity({ title }). A hook with live state of its own returns an object with the function, its “-ing” flag and that state instead:const { uploadImage, uploading, progress } = useUploadImage(), and the same foruseUploadFile. - Functions on a data hook take one object too:
updateRow({ rowId, data }), and the list fetchesfetchEntities({ filters, sort, config, options }),fetchSpaces({ filters, config, options })andfetchWorkspaces({ filters, config, options }), whose groups stay apart because they behave differently (filtersmerge into the current ones,sortandconfigare the list’s settings,optionscontrol the one fetch). Outside production builds (in development and in test runs), a key other than those groups logs a warning (it would otherwise be ignored). - Setters on a data hook take their one value directly, like React’s
setState:setSortBy("top"),setRsvp("going"),setShowReplyBanner(true).
SublayError
SublayError extends Error and is exported from @sublay/core (and so from @sublay/react-js, @sublay/react-native and @sublay/expo). It is what a hook’s error field holds and what a hook’s functions reject with: a request the server refused, a request that never got an answer, and a check the SDK makes before sending (for example a call made with no project, which has no code).
When the server answered, the
error text of its response. Otherwise what went wrong on the way: no network, a timeout, or a failure inside the SDK."SublayError", or the subclass’s name ("SuspendedError", "AccountTransitionError"). An aborted request keeps its abort name: "CanceledError" or "AbortError".The server’s machine-readable error code, such as
"space/not-found" or "user/suspended". Present only when the server answered with one; there is no code for a network error or a failure inside the SDK.The request field the error is about, when the server names one (for example
"username").The server’s JSON error body exactly as sent:
error, code, param and any extra fields a response carries (each hook’s page lists them), such as ownedWorkspaces and ownedCount, missingTables, verificationId, or a 500’s details. Present only when the server answered with a JSON object; a non-JSON answer (an HTML error page) and a failure with no answer have no body.code, which stays the same when the server rewords a message:
isSublayError(err) to err instanceof SublayError: it also recognises a SublayError made by another installed copy of the SDK, which instanceof misses.
toSublayError(err) turns any other caught value into a SublayError the same way (a SublayError is returned unchanged), for code that mixes the SDK’s calls with your own. SuspendedError and AccountTransitionError are SublayErrors with fields of their own.
List hooks
Every hook that returns a paged list with paging controls (useEntityList, useSpaceList, useWorkspaceList, useAppNotifications, useConversations, useLiveChatMessages, useMessageThread, useEntityComments, useCommentSection, useReplies and the use…Wrapper hooks) returns the same controls. useConversationData and the ConversationProvider context (useConversationContext) return them for the conversation’s messages as messagesLoading, messagesError, hasMore, loadMore and refetchMessages, beside the members:
loading: boolean—truewhile a page is loading.error: SublayError | null— the last load failure, as aSublayError. Cleared when the next load starts.hasMore: boolean— whetherloadMore()has anything to fetch: a next page, or a load that failed. After a failure it istrue.loadMore: () => Promise<void>— loads the next page in the list’s own reading order, or retries the load that failed (a failed first page is retried as the first page). Does nothing while a load is running or when there is nothing more. Never rejects: failures land inerror.refetch: () => Promise<void>— reloads from the first page with the current filters and sort. What is loaded stays until the new first page replaces it (each hook’s page says what it keeps beyond that page, e.g. a comment section keeps the viewer’s new comments and loaded replies). Never rejects.
loadMore() while error is set: hasMore stays true after a failure, so an automatic trigger would retry over and over while the server keeps failing. Show the error with a “Try again” button that calls loadMore() instead, as in the example below.
A response that arrives after the query changed (new filters, sort or ids, or a refetch that started since) is dropped. Two loadMore() calls in the same tick load one page, and filter objects or include arrays written inline don’t cause refetching.
The store-backed lists (useEntityList, useSpaceList, useWorkspaceList, useAppNotifications, useConversations, useLiveChatMessages) share loading, error and paging across every mounted hook on the same list: the same listId, the same conversation or thread, the one notifications list, the one inbox. Two hooks opening the same conversation (a ConversationProvider and a useLiveChatMessages inside it with its own include, for example) both load, and what each brings is merged; a refetch of the conversation keeps, on the messages it brings again, the files / grants the other hook fetched, except what the server hides on a deleted or removed message: its files (its author still sees the files of their own removed message) and a removed message’s grants. On useEntityList, useSpaceList and useWorkspaceList, loadMore also does nothing while a debounced filter change is waiting to be fetched. An account change empties them and clears their errors; a load still in flight for the previous account is dropped.
useCollectionEntitiesWrapper is in between: the entities live in the shared store under the collection (so saving or removing an entity updates every hook showing that collection), but each hook pages and sorts on its own. Show a collection’s entities with one hook at a time; a second hook on the same collection replaces them with its own first page.
Every other use…Wrapper hook keeps its list in the component and starts over when its props, the project or the signed-in user change.

