VOOZH about

URL: https://www.geeksforgeeks.org/reactjs/reactjs-ui-ant-design-checkbox-component/

⇱ ReactJS UI Ant Design Checkbox Component - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ReactJS UI Ant Design Checkbox Component

Last Updated : 21 May, 2021

Ant Design Library has this component pre-built, and it is very easy to integrate as well. The checkbox component allows the user to make a binary choice from the given options. We can use the following approach in ReactJS to use the Ant Design Checkbox Component.

Checkbox Methods:

  • blur(): This method is used to remove the focus from the element.
  • focus(): This method is used to get the focus on the element.

Checkbox Props:

  • autoFocus: It is used to get focus when the component is mounted.
  • checked: It indicates whether the checkbox is selected or not.
  • defaultChecked: It is used to specify the initial state whether the checkbox is selected or not.
  • disabled: It is used to disable the checkbox.
  • indeterminate: It is used to denote the indeterminate checked state of the checkbox.
  • onChange: It is the callback function which is triggered when state changes.

Checkbox Group Props:

  • defaultValue: It is used to define the default selected value for the checkbox.
  • disabled: It is used to disable all checkboxes.
  • name: It is used to define the name property of all input children which are of type checkbox.
  • options: It is used to specify options.
  • value: It is used for setting the currently selected value.
  • onChange: It is the callback function which is triggered when state changes.

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 antd

Project Structure: It will look like the following.

👁 Image
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.

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:

👁 Image

Reference: https://ant.design/components/checkbox/

Comment
Article Tags: