Thursday, July 4, 2024
HomeLanguagesJavascriptReact Suite CheckTree Component

React Suite CheckTree Component

React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. CheckTree component allows the user to show tree-structured data, and it supports the Checkbox selection. We can use the following approach in ReactJS to use the React Suite CheckTree Component.

CheckTree Props:

  • cascade: It is used to indicate whether to enable cascade selection or not.
  • childKey: It is used to set the children key in the data.
  • data: It is used to denote the selectable data.
  • defaultExpandAll: It is used to expand all nodes by default.
  • defaultValue: It is used to denote the default value.
  • defaultExpandItemValues: It is used to set the value of the default expanded node.
  • disabledItemValues: It is used to disable optional.
  • expandItemValues: It is used to set the value of the expanded node (controlled).
  • height: It is used to denote the menu height.
  • labelKey: It is used to set the options to display the ‘key’ in ‘data’.
  • onChange: It is a callback function that is triggered when value changes.
  • onExpand: It is a callback function that is triggered when the tree node is displayed.
  • onSelect: It is a callback function that is triggered on the selection of an option.
  • renderTreeIcon: It is used to denote the custom render icon.
  • renderTreeNode: It is used to denote the custom render tree node.
  • searchKeyword: It is used to denote the search keyword (Controlled).
  • uncheckableItemValues: It is used to set the option value for the checkbox not to be rendered.
  • value: It is used to denote the value (Controlled).
  • valueKey: It is used to set the option value ‘key’ in ‘data’.
  • virtualized: It is used to indicate whether using Virtualized List or not.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:

    npx create-react-app foldername
  •  

  • Step 2: After creating your project folder i.e. foldername, move to it using the following command:

    cd foldername
  • Step 3: After creating the ReactJS application, Install the required module using the following command:

    npm install rsuite

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React from 'react'
import 'rsuite/dist/styles/rsuite-default.css';
import { CheckTree } from 'rsuite';
  
export default function App() {
  
  // Sample Options
  const options = [
    {
      "label": "Madhya Pradesh",
      "value": 1,
      "children": [
        {
          "label": "Mhow",
          "value": 2
        },
        {
          "label": "Indore",
          "value": 3,
          "children": [
            {
              "label": "Vijay Nagar",
              "value": 4
            },
            {
              "label": "Rajiv Gandhi Square",
              "value": 5
            },
            {
              "label": "MR 10",
              "value": 6
            },
          ]
        },
      ]
    }
  ]
  
  return (
    <div style={{
      display: 'block', width: 600, paddingLeft: 30
    }}>
      <h4>React Suite CheckTree Component</h4>
      <CheckTree
        style={{ width: 300 }}
        defaultExpandAll
        data={options}
      />
    </div>
  );
}


Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://rsuitejs.com/components/check-tree/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nango Kalahttps://www.kala.co.za
Experienced Support Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Microsoft Excel, Customer Service, Microsoft Word, Technical Support, and Microsoft Office. Strong information technology professional with a Microsoft Certificate Solutions Expert (Privet Cloud) focused in Information Technology from Broadband Collage Of Technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments