use-list-selection-management-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Use List Selection Management

Introduction

This hook is used to provide auxiliary data related to selection status of a list, as well as utility functions to manipulate selection status of list items.

Example

import useListSelectionManagement from "use-list-selection-management";

const data = [
    {id:"1"},
    {id:"2"},
    {id:"3"},
    {id:"4"},
]

const {
    totalItemsCount, //count total items in the list
    selectedItems, //partial list of selected items
    selectedItemsCount,  //count total items in the list
    isAllSelected, // A boolean indicating whether all items are selected
    isSomeButNotAllSelected, // A boolean indicating whether some but not all items are selected
    toggleThisItem, // A function to change selection status of an item
    toggleAllItems, // A function to change selection status of all items in the list
    listSelectionMap, // The map that record selection status of items in the list
  } = useListSelectionManagement(
    data, // An array of items
    (i) => i.id), // A function that returns the id of the item, help recognize them

Package Sidebar

Install

npm i use-list-selection-management-hook

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

17.3 kB

Total Files

9

Last publish

Collaborators

  • tuanbk1908