useFetchSingleEntity
Overview
The useFetchSingleEntity
hook is used to retrieve details of a specific entity by providing one of its identifiers, such as entityId
, referenceId
, or shortId
. This hook can optionally create a new entity if it is not found, depending on the configuration provided during initialization.
Usage Example
import { useFetchSingleEntity } from "@replyke/react-js";
function EntityDetails({ entityId }: { entityId: string }) {
const fetchSingleEntity = useFetchSingleEntity();
const handleFetchEntity = async () => {
try {
const entity = await fetchSingleEntity({
entityId,
});
console.log("Fetched entity:", entity);
} catch (error) {
console.error("Failed to fetch entity:", error.message);
}
};
return <button onClick={handleFetchEntity}>Fetch Entity Details</button>;
}
Parameters & Returns
Parameters
The hook returns a function that accepts an object with the following fields:
Parameter | Type | Required | Description |
---|---|---|---|
entityId | string | No | The unique ID of the entity to fetch. |
referenceId | string | No | A reference ID that can be used to identify the entity. |
shortId | string | No | A short identifier for the entity. |
At least one of entityId
, referenceId
, or shortId
must be provided.
Returns
The function resolves with an object representing the fetched entity:
Return Value | Type | Description |
---|---|---|
Entity | object | The details of the retrieved entity. |