useIsEntitySaved

Overview

The useIsEntitySaved hook is used to determine whether a specific entity is saved in the user’s lists. It provides a simple mechanism to check the saved status of an entity and cache the result to avoid redundant requests.

Usage Example

import { useIsEntitySaved } from "@replyke/react-js";
 
function EntitySaveStatus({ entityId }: { entityId: string }) {
  const { checkIfEntityIsSaved, entityIsSaved } = useIsEntitySaved();
 
  useEffect(() => {
    checkIfEntityIsSaved(entityId);
  }, [entityId, checkIfEntityIsSaved]);
 
  return (
    <div>
      {entityIsSaved === null ? "Checking..." : entityIsSaved ? "Entity is saved" : "Entity is not saved"}
    </div>
  );
}

Parameters & Returns

Parameters

The hook provides a function that accepts the following parameter:

ParameterTypeRequiredDescription
entityIdstringYesThe ID of the entity to check.

Returns

The hook returns the following:

Return ValueTypeDescription
checkIfEntityIsSaved(entityId: string) => voidA function to check if the specified entity is saved.
entityIsSavedboolean | nullThe saved status of the entity (true, false, or null if not yet checked).