Skip to main content

Overview

useFetchEntity returns a function that fetches a single entity by its Replyke entity ID. Use this for on-demand fetches outside of EntityProvider.

Usage Example

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

function EntityLoader({ entityId }: { entityId: string }) {
  const fetchEntity = useFetchEntity();

  const load = async () => {
    const entity = await fetchEntity({ entityId, include: ["user", "topComment"] });
    console.log(entity);
  };

  return <button onClick={load}>Load Entity</button>;
}

Parameters

entityId
string
required
The Replyke entity ID to fetch.
include
string | string[]
Optional. Populate related fields. Accepted values: "user", "space", "topComment", "saved", "files".

Returns

Entity
Entity
The fetched entity. See Entity data model.