Skip to main content
Requires the entities bundle. A project without the entities bundle returns 403 database/tables-not-available. See Bundles.

Overview

useEntity reads from the nearest EntityProvider in the component tree and returns the entity’s state and actions. It does not fetch data itself — it accesses what EntityProvider has already loaded. Which related data the entity carries (user, space, topComments, saved, files, grants) is set by the provider’s include prop, along with topCommentsLimit and topCommentsSortByReaction:
See EntityProvider props.
useEntity must be used inside an EntityProvider. See EntityProvider & useEntity for setup instructions.

Usage Example

Return Values

Entity | null | undefined
The current entity. undefined while loading, null if not found.
React.Dispatch
Direct state setter for the entity. Use for manual local state overrides.
(changes: Omit<UpdateEntityProps, "entityId">) => Promise<Entity | undefined>
Updates the entity on the server and syncs local state. Takes the changes alone, e.g. updateEntity({ title }): the fields of useUpdateEntity without entityId, i.e. title, content, attachments, keywords, location, metadata, mentions, nsfw, images and files (appended, sent as multipart), removeFileIds and include.
() => Promise<void>
Deletes the entity and sets local state to undefined.