rc-cascader (Legacy)
This package, `rc-cascader`, is a foundational React UI component providing a robust and unstyled cascader (hierarchical select) control. Its latest official release under this name is version 3.34.0. While stable for existing applications, new development should strongly consider migrating to its successor, `@rc-component/cascader`, which is the actively maintained and refactored version of this component (starting with `@rc-component/cascader` v1.8.0). `rc-cascader` emphasizes core functionality and accessibility, providing the logic for hierarchical selection without imposing specific styling, making it highly adaptable for integration into custom design systems like Ant Design. It depends on `react` and `react-dom` versions 16.9.0 or higher.
Common errors
-
Module not found: Can't resolve 'rc-cascader' in '...'
cause The package `rc-cascader` is not installed, or you are attempting to import it while `rc-cascader` has been uninstalled in favor of `@rc-component/cascader`.fixEnsure `rc-cascader` is listed in your `package.json` and installed (`npm install rc-cascader`). If migrating, update imports to `import Cascader from '@rc-component/cascader';` after installing the new package. -
TypeError: Cannot read properties of undefined (reading 'render')
cause This error often occurs in modern React setups when `React.render` is called directly. `React.render` has been deprecated since React 18, which uses `ReactDOM.createRoot().render()`.fixFor React 18+, use `import ReactDOM from 'react-dom/client'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />);`. For older React versions, ensure you have `import ReactDOM from 'react-dom';` and call `ReactDOM.render(<App />, document.getElementById('root'));`.
Warnings
- breaking The `rc-cascader` package has been superseded and effectively renamed to `@rc-component/cascader`. All active development, bug fixes, and new features are now exclusively released under the `@rc-component/cascader` package (starting with its v1.8.0 release).
- gotcha The `rc-cascader` component provides unstyled logic. If you are expecting a fully styled component, you will need to apply your own CSS or integrate it within a design system like Ant Design which provides its own styling for this component.
- gotcha The `Cascader` component in its raw form requires a child element to act as its trigger. If no child is provided, the component might not render correctly or be interactable.
Install
-
npm install rc-cascader -
yarn add rc-cascader -
pnpm add rc-cascader
Imports
- Cascader
const Cascader = require('rc-cascader');import Cascader from 'rc-cascader';
- CascaderProps
import type { CascaderProps } from 'rc-cascader'; - Cascader
import Cascader from '@rc-component/cascader';
import Cascader from 'rc-cascader';
Quickstart
import React from 'react';
import ReactDOM from 'react-dom';
import Cascader from 'rc-cascader';
const options = [{
'label': '福建',
'value': 'fj',
'children': [{
'label': '福州',
'value': 'fuzhou',
'children': [{
'label': '马尾',
'value': 'mawei',
}],
}, {
'label': '泉州',
'value': 'quanzhou',
}],
}, {
'label': '浙江',
'value': 'zj',
'children': [{
'label': '杭州',
'value': 'hangzhou',
'children': [{
'label': '余杭',
'value': 'yuhang',
}],
}],
}, {
'label': '北京',
'value': 'bj',
'children': [{
'label': '朝阳区',
'value': 'chaoyang',
}, {
'label': '海淀区',
'value': 'haidian',
}],
}];
const App = () => (
<div style={{ padding: 20 }}>
<h2>Cascader Example</h2>
<Cascader options={options} placeholder="Please select">
<input style={{ width: 200, padding: 8, borderRadius: 4, border: '1px solid #ccc' }} readOnly value="Select region" />
</Cascader>
</div>
);
ReactDOM.render(<App />, document.getElementById('root'));