React & React NativeHooksEntitiesuseCreateEntity

useCreateEntity

Overview

The useCreateEntity hook is used to create a new entity within the project. It handles all required parameters for the creation process and associates the entity with the currently logged-in user.

Usage Example

import { useCreateEntity } from "@replyke/react-js";
 
function CreateEntityForm() {
  const createEntity = useCreateEntity();
 
  const handleCreateEntity = async () => {
    try {
      const result = await createEntity({
        title: "My New Entity",
        content: "This is the content of the entity.",
        media: ["https://example.com/image.jpg"],
        keywords: ["example", "entity"],
        location: { latitude: 40.7128, longitude: -74.0060 },
        metadata: { category: "blog" },
      });
 
      console.log("Entity created successfully:", result);
    } catch (error) {
      console.error("Failed to create entity:", error.message);
    }
  };
 
  return <button onClick={handleCreateEntity}>Create Entity</button>;
}

Parameters & Returns

Parameters

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

ParameterTypeRequiredDescription
referenceIdstringNoAn optional reference ID to associate with the entity.
titlestringNoThe title of the entity.
contentstringNoThe main content of the entity.
mediaany[]NoAn array of media items (e.g., images, videos) associated with the entity.
keywordsstring[]NoAn array of keywords to tag the entity.
locationobjectNoThe geographic location (latitude, longitude) associated with the entity.
metadataRecord<string, any>NoAdditional metadata to store with the entity.

Returns

The function resolves with an object representing the newly created entity:

Return ValueTypeDescription
EntityobjectThe details of the created entity, including its ID, title, and other attributes.