React & React NativeHooksListsuseCreateList

useCreateList

Overview

The useCreateList hook is used to create a new list within the current project. The newly created list is associated with a parent list, enabling the creation of hierarchical list structures.

Usage Example

import { useCreateList } from "@replyke/react-js";
 
function CreateListButton({ parentListId }: { parentListId: string }) {
  const createList = useCreateList();
 
  const handleCreateList = async () => {
    try {
      const newList = await createList({
        listName: "My New List",
        parentListId,
      });
 
      console.log("List created successfully:", newList);
    } catch (error) {
      console.error("Failed to create list:", error.message);
    }
  };
 
  return <button onClick={handleCreateList}>Create List</button>;
}

Parameters & Returns

Parameters

The hook returns a function that accepts an object with the following fields:

ParameterTypeRequiredDescription
listNamestringYesThe name of the new list to be created.
parentListIdstringYesThe ID of the parent list under which the new list is created. Each user has a root list to serve as parent if creating a first level list.

Returns

The function resolves with an object representing the newly created list:

Return ValueTypeDescription
ListListThe new created list object.