Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-checkbox-tree

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-checkbox-tree

React hook for checkbox tree component

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
394
increased by140.24%
Maintainers
1
Weekly downloads
 
Created
Source

use-checkbox-tree

React hook for checkbox tree component

Tests Version License

Installation

npm i use-checkbox-tree

Usage

import ReactDOM from 'react-dom';
import useCheckboxTree from 'use-checkbox-tree';

const nodes = [
  {
    id: 1,
    children: [
      {
        id: 1.1,
      },
      {
        id: 1.2,
      },
    ],
  },
];

const initialValue = [];

const TreeComponent = () => {
  const { checked, indeterminates, state, selectNode } = useCheckboxTree(nodes, initialValue);

  // checked -> [1.2]
  // indeterminates -> [1]
  // state.get(1) -> 'indeterminate'

  return (
    // iterate through nodes and create your own tree view
    <div />
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<TreeComponent />);

Return values

  • checked - array of selected node ids
  • selectNode - a function to select node
  • deSelectNode - a function to deselect node
selectNode(1); // select a node
deSelectNode(1); // deselect a node
selectNode(1, true); // select a node
selectNode(1, false); // deselect a node
  • clear - a function to clear all selected items

  • state - object with id as key and value as boolean | indeterminate

Map{
  1: "indeterminate",
  1.1: true,
  1.2: false
}

Keywords

FAQs

Package last updated on 03 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc