useAddToList
Overview
The useAddToList
hook is used to add an entity to an existing list within the current project. This allows users to organize entities under specific lists for better categorization and management.
Usage Example
import { useAddToList } from "@replyke/react-js";
function AddToListButton({ entityId, currentList }: { entityId: string; currentList: List }) {
const addToList = useAddToList();
const handleAddToList = async () => {
try {
const updatedList = await addToList({
entityId,
currentList,
});
console.log("Entity added to list successfully:", updatedList);
} catch (error) {
console.error("Failed to add entity to list:", error.message);
}
};
return <button onClick={handleAddToList}>Add to List</button>;
}
Parameters & Returns
Parameters
The hook returns a function that accepts an object with the following fields:
Parameter | Type | Required | Description |
---|---|---|---|
entityId | string | Yes | The ID of the entity to be added to the list. |
currentList | List | Yes | The list to which the entity will be added. |
Returns
The function resolves with an object representing the updated list:
Return Value | Type | Description |
---|---|---|
List | List | The details of the updated list, including the added entity. |