Skip to main content

Overview

useCreateEntity returns a function that creates a new entity. It supports both JSON and multipart form requests — the hook automatically selects multipart when images or files are included.

Usage Example

import { useCreateEntity } from "@replyke/react-js";

function NewPost() {
  const createEntity = useCreateEntity();

  const handleCreate = async () => {
    const entity = await createEntity({
      title: "Hello World",
      content: "My first post",
      keywords: ["intro", "welcome"],
    });
    console.log("Created:", entity.id);
  };

  return <button onClick={handleCreate}>Create Post</button>;
}

With image upload

const entity = await createEntity({
  title: "Photo post",
  images: {
    files: [imageFile],
    options: { width: 1200, height: 800, fit: "cover" },
  },
});

Parameters

foreignId
string
An ID from your own system to link this entity to an existing item.
sourceId
string
An identifier for grouping entities by source (e.g., a section of your app).
spaceId
string
The ID of the space this entity belongs to.
title
string
Entity title.
content
string
Entity body content.
attachments
Record<string, any>[]
Array of attachment objects. Flexible structure — can represent media URLs, file metadata, or any structured data.
keywords
string[]
Tags or keywords for filtering and discovery.
mentions
Mention[]
Users mentioned in the entity content.
location
{ latitude: number; longitude: number }
Geographic location for the entity.
metadata
Record<string, any>
Arbitrary project-specific data. Limited to 10 KB.
isDraft
boolean
If true, creates the entity as a draft (not publicly visible). Default false.
excludeUserId
boolean
If true, the authenticated user is not associated as the entity author.
requireUser
boolean
If true, the request fails if no authenticated user is present.
images
{ files: File[]; options?: UploadImageOptions }
Images to upload and attach. Triggers a multipart form request.
files
{ files: File[]; options?: { pathParts?: string[] } }
Files to upload and attach. Triggers a multipart form request.

Returns

Entity
Entity
The newly created entity. See Entity data model.