rc-mentions is a foundational React component designed for building rich `@`-mentions input functionalities within web applications. It provides the core logic and UI structure for user mentions, offering a highly customizable experience without dictating specific styling. The current stable version, `2.20.0`, is actively maintained, with frequent minor and patch releases indicated by the project's recent activity, though specific release notes for major version `2` are not immediately visible in the provided data. Key differentiators include its broad browser compatibility (supporting IE9+, Chrome, Firefox, Safari), robust keyboard navigation for accessibility, and a flexible API that allows developers full control over filtering options and popup placement. Unlike opinionated UI libraries, `rc-mentions` ships unstyled, requiring developers to provide their own CSS (typically from its Less source) for integration into their design system.
npm install rc-mentionsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic usage of `rc-mentions`, showing how to import the component, its required styles, define options, and render it in a React application. It includes placeholder text and simple `onSelect`/`onChange` handlers.
Check the project's README and documentation on GitHub (`react-component/mentions`) to confirm the correct package name and version for your needs. If migrating, review any provided upgrade guides.
Configure your build tool (e.g., Webpack, Rollup) to process `.less` files using a Less loader (`less-loader` for Webpack). Alternatively, you can pre-compile `index.less` to CSS and import the resulting `.css` file into your project.
Ensure your project's `react` and `react-dom` packages are updated to version `16.9.0` or newer to satisfy the peer dependency requirements. Run `npm install react@^16.9.0 react-dom@^16.9.0` or `yarn add react@^16.9.0 react-dom@^16.9.0`.
Always access `Option` as a property of the `Mentions` component after it has been imported. For ESM, use `const { Option } = Mentions;`. For CommonJS, use `const Mentions = require('rc-mentions'); const Option = Mentions.Option;`.Ensure your build configuration (e.g., Webpack with `less-loader`) is set up to handle `.less` files, or pre-compile `index.less` to CSS and import the resulting `.css` file.
Access `Option` as a property of the `Mentions` component: `import Mentions from 'rc-mentions'; const { Option } = Mentions;`.Upgrade `react` and `react-dom` to `^16.9.0` or newer versions that satisfy the peer dependency requirements.
Add `import 'rc-mentions/assets/index.less';` to your entry file or component (and ensure your build system processes Less files), or ensure the compiled CSS is correctly linked.