React Checkbox Component

3.5.0 · renamed · verified Sun Apr 19

rc-checkbox is a foundational, unstyled React UI component that provides a customizable checkbox input. It aims to offer a robust and accessible base for building more elaborate checkbox UIs. The current stable version is 3.5.0. While active development for this component has effectively transitioned to the `@rc-component/checkbox` namespace, `rc-checkbox` version 3.5.0 remains available on npm. Its release cadence was moderate, with a significant rewrite to TypeScript in v3.0.0, and it differentiates itself by offering a simple, highly composable core component without imposing specific styling frameworks. Users seeking the latest features and ongoing maintenance should consider migrating to the `@rc-component/checkbox` package.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the `rc-checkbox` component, managing its checked state and handling changes. It also shows examples of disabled checkboxes and the necessary CSS import.

import React, { useState } from 'react';
import Checkbox from 'rc-checkbox';
import 'rc-checkbox/assets/index.css'; // Don't forget to import the default styles if needed

const MyCheckboxComponent = () => {
  const [isChecked, setIsChecked] = useState(false);

  const handleChange = (e) => {
    setIsChecked(e.target.checked);
    console.log('Checkbox changed:', e.target.checked);
  };

  return (
    <div>
      <label>
        <Checkbox
          checked={isChecked}
          onChange={handleChange}
          name="myAwesomeCheckbox"
          id="my-awesome-checkbox"
        />
        <span>{isChecked ? 'Checked' : 'Unchecked'}</span>
      </label>
      <br />
      <label>
        <Checkbox defaultChecked disabled />
        <span>Disabled and Checked</span>
      </label>
      <br />
      <label>
        <Checkbox disabled />
        <span>Disabled and Unchecked</span>
      </label>
    </div>
  );
};

export default MyCheckboxComponent;

view raw JSON →