React Component Input
rc-input is a foundational, unstyled React input component, designed to be highly customizable and often used as a building block for UI libraries like Ant Design. It provides core input functionalities, including features like clearable input. The current stable version is 1.8.0. It receives regular maintenance updates, though a strict release cadence isn't published. A key differentiator is its low-level nature, focusing purely on input logic without opinionated styling, making it highly adaptable. It provides full TypeScript support and manages common input behaviors such as value synchronization and focus handling. The package has a somewhat convoluted naming history, which developers should be aware of.
Common errors
-
Module not found: Can't resolve '@rc-component/input'
cause Attempting to import from `@rc-component/input` when the actively maintained and installed package is `rc-input`.fixChange your import statements from `import ... from '@rc-component/input'` to `import ... from 'rc-input'`. -
TypeError: (0, _rc_input.default) is not a function
cause Attempting to use `require('rc-input')` directly as a function in CommonJS, when `rc-input` exports its main component as a default export.fixAccess the default export correctly: `const Input = require('rc-input').default;` -
TypeError: Cannot read properties of undefined (reading 'TextArea')
cause Attempting to use `Input.TextArea` without `Input` being correctly imported or when the installed version of `rc-input` does not expose `TextArea` in this manner.fixEnsure `import Input from 'rc-input';` is correctly placed and that your `rc-input` version supports the `Input.TextArea` static component. If it doesn't, you might need to use a separate `rc-textarea` package or upgrade `rc-input`.
Warnings
- breaking The package underwent a confusing naming change attempt. At one point, the project intended to rename from `rc-input` to `@rc-component/input`. While a separate `@rc-component/input` package exists with its own `1.x` release line, the original `rc-input` package has continued independent development and is now at a higher version (e.g., 1.8.0 vs. 1.3.0 for `@rc-component/input`). Developers should strictly use `rc-input` for the actively maintained version.
- breaking Textarea functionality, previously potentially handled by a separate `rc-textarea` package or distinct component, was merged into `rc-input` (noted in `@rc-component/input@1.3.0`, which should apply to the `rc-input` line as well). This change consolidates input and textarea logic. Users of `rc-textarea` or specific textarea APIs should review the `rc-input` documentation for the new recommended way to implement text areas.
- gotcha The README contains incorrect NPM links pointing to `rc-select` instead of `rc-input` for bundle size and download stats. This is a documentation error and does not affect package functionality, but can be misleading when checking package popularity or size.
Install
-
npm install rc-input -
yarn add rc-input -
pnpm add rc-input
Imports
- Input
import { Input } from 'rc-input';import Input from 'rc-input';
- Input.TextArea
import { TextArea } from 'rc-input';import Input from 'rc-input'; // ... <Input.TextArea />
- CommonJS require
const Input = require('rc-input');const Input = require('rc-input').default;
Quickstart
import Input from 'rc-input';
import { createRoot } from 'react-dom/client';
const App = () => (
<div>
<Input placeholder="Basic input" allowClear />
<br />
<Input.TextArea placeholder="Textarea input" rows={4} />
<br />
<Input value="Readonly input" readOnly />
</div>
);
const mountNode = document.getElementById('root');
if (mountNode) {
const root = createRoot(mountNode);
root.render(<App />);
} else {
console.error('Mount node not found!');
}