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

Overview

useUpdateEntity returns a function that updates an entity’s content fields, and adds or removes its files. Pass images and files to append files (the request is then sent as multipart) and removeFileIds to remove the entity’s files. After a successful update, the nearest EntityProvider shows the edit when it holds the same entity (one holding another entity is left as it is), and so does every loaded entity list holding it: the response’s fields replace those of the provider’s and the list’s copy, and fields the response doesn’t carry or doesn’t fill for the viewer (such as saved, space, the viewer’s userReaction and the author’s files) are kept. The response carries the entity’s files only with include: "files"; then they replace the copy’s. The hook sends include: "files" itself when the update uploads or removes files (and you passed no include), so the copies get the new list; a response without files leaves the copies’ files as they are.

Usage Example

Parameters

string
required
The ID of the entity to update.
The changes go next to entityId, all optional, not inside an update object (an update key throws a SublayError before anything is sent).
string
New title.
string
New content body.
Record<string, any>[]
Replacement attachments array.
string[]
Replacement keywords array.
{ latitude: number; longitude: number }
New geographic location.
Record<string, any>
Replacement metadata object.
Mention[]
Updated mentions array.
boolean
Updated NSFW own-flag. Subject to the same owner / service authorization as the rest of the update. To flag another user’s entity, a space moderator uses useSetSpaceEntityNsfw instead. See Entity NSFW flagging.
{ files: UploadFileInput[]; options: UploadImageOptions }
Images to append after the entity’s files, processed into sizes per options (mode is required). Each file is a File or Blob, or a React Native file { uri, name, type? }. Sends multipart. Requires the files-images bundle.
{ files: UploadFileInput[]; options?: { pathParts?: string[] } }
Files to append after the entity’s files, stored as uploaded. Sends multipart. Requires the files-images bundle.
"files" | "files"[]
What the response adds: "files", the entity’s files as they now are. Defaults to "files" when the update uploads or removes files; otherwise the response has no files.
string[]
Ids of the entity’s files to remove (ids in its files). Works alone or with uploads. Any other id refuses the whole update (400 entity/invalid-remove-file-ids, with invalidIds).

Returns

Entity
The updated entity. See Entity data model.