useUpdateEntity

Overview

The useUpdateEntity hook is used to update the details of an existing entity. It allows for partial updates, meaning only the provided fields will be modified while other fields remain unchanged.

Usage Example

import { useUpdateEntity } from "@replyke/react-js";
 
function UpdateEntityForm({ entityId }: { entityId: string }) {
  const updateEntity = useUpdateEntity();
 
  const handleUpdateEntity = async () => {
    try {
      const updatedEntity = await updateEntity({
        entityId,
        update: {
          title: "Updated Title",
          content: "Updated content of the entity.",
          keywords: ["updated", "entity"],
          location: { latitude: 40.7128, longitude: -74.0060 },
          metadata: { category: "updated category" },
        },
      });
 
      console.log("Entity updated successfully:", updatedEntity);
    } catch (error) {
      console.error("Failed to update entity:", error.message);
    }
  };
 
  return <button onClick={handleUpdateEntity}>Update Entity</button>;
}

Parameters & Returns

Parameters

The hook returns a function that accepts an object with the following fields:

ParameterTypeRequiredDescription
entityIdstringYesThe ID of the entity to be updated.
updateobjectYesAn object containing the fields to update.
update.titlestring | nullNoThe new title for the entity.
update.contentstring | nullNoThe new content for the entity.
update.mediaRecord<string, any>[]NoThe updated media items for the entity.
update.keywordsstring[]NoThe updated keywords for the entity.
update.locationobjectNoThe new geographic location for the entity.
update.metadataRecord<string, any>NoAdditional metadata to update for the entity.

Returns

The function resolves with an object representing the updated entity:

Return ValueTypeDescription
EntityobjectThe details of the updated entity.