Skip to main content

Overview

The useCollections hook gives you a navigable view of the user’s collection tree. It automatically fetches the root collection on mount and loads sub-collections as you navigate deeper.

Setting Up

useCollections requires a logged-in user. It reads the user and project context from the nearest SublayProvider.
The hook maintains a navigation stack. Calling openCollection pushes a collection onto the stack and fetches its sub-collections. goBack pops the stack; goToRoot resets to the root.

Creating Sub-collections

createCollection creates a new sub-collection inside the current collection.
You cannot create a collection at the root of useCollections — there is no concept of “creating inside root” vs “creating inside a sub-collection” from the hook’s perspective. The current collection is always the parent.

Renaming a Collection

The root collection cannot be renamed.

Deleting a Collection

The root collection cannot be deleted. When a collection is deleted, the navigation state automatically moves back to the parent.

Saving and Removing Entities

addToCollection saves an entity into the current collection. removeFromCollection removes it.

Checking If an Entity Is Saved

isEntitySaved queries whether a specific entity is saved anywhere in the user’s collections. Optionally pass a collectionId to check a specific folder.

Displaying Collection Entities

Use useCollectionEntitiesWrapper to fetch the paginated list of entities saved in a collection.