Skip to main content

Overview

useCollectionsActions exposes every collection action as a standalone callable function. It is used internally by useCollections but can also be used directly when you need fine-grained control over collection operations without the navigation state. Every action works in the project of the nearest SublayProvider.
For most use cases, prefer useCollections — it combines these actions with navigation state. Use useCollectionsActions only when you need to perform actions independently of a navigation context.

Usage Example

Returns

(collection: Collection) => void
Push a collection onto the Redux navigation stack.
() => void
Pop the current collection from the navigation stack.
() => void
Reset navigation to the root collection.

Data Fetching

() => Promise<void>
Fetch and set the user’s root collection in Redux state.
({ collectionId }: { collectionId: string }) => Promise<void>
Fetch sub-collections for a given collection and update Redux state.

CRUD Operations

({ parentCollectionId, name }: { parentCollectionId: string; name: string }) => Promise<void>
Create a new sub-collection under the specified parent collection. Navigates into the new collection after creation.
({ collectionId, name }: { collectionId: string; name: string }) => Promise<void>
Update a collection’s name, passed next to collectionId. Loaded entity lists that list the collection in saved show the new name.
({ collection }: { collection: Collection }) => Promise<{ deletedCollectionIds: string[] } | undefined>
Delete a collection and every collection under it. Once it succeeds, it resolves to { deletedCollectionIds } (the deleted collection and every collection under it), and the deleted collections leave Redux state. If the current collection is one of them, navigation moves back to the most recent collection in the history that wasn’t deleted; otherwise it stays where it is. Entity lists loaded with useEntityList that carry saved drop the deleted collections from each entity’s saved.collections, with isSaved staying true only while another collection is listed. Resolves to undefined when the delete fails.
({ collectionId, entity }: { collectionId: string; entity: Entity }) => Promise<void>
Add an entity to a collection by creating a junction table entry. Once it succeeds, loaded entity lists that carry saved (fetched with include=saved) add the collection, with the name the response gives, to the entity’s saved.collections and set isSaved to true.
({ collectionId, entityId }: { collectionId: string; entityId: string }) => Promise<void>
Remove an entity from a collection. Once it succeeds, loaded entity lists that carry saved drop the collection from the entity’s saved.collections; isSaved stays true only while another collection is listed.

Utility

() => void
Clear all collections state from Redux (e.g., on sign-out).