react-highlight-words is a React component designed to highlight specific words or phrases within a larger body of text. It is currently stable at version v0.21.0, which includes support for React 19. The package primarily sees updates for compatibility with newer React versions and minor feature additions, indicating a consistent but not overly frequent release cadence. Key differentiators include its straightforward API, support for regular expression `searchWords`, automatic escaping of special characters via `autoEscape`, and the ability to apply specific styling or classes to an 'active' match using `activeIndex` and `activeClassName`, making it suitable for search result navigation or interactive text features. It provides a robust solution for visually emphasizing text segments based on user-defined criteria.
npm install react-highlight-wordsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of the Highlighter component, highlighting multiple search words within a given text and applying a custom class to matches.
Always set `autoEscape={true}` if search words are not strictly controlled or contain potential RegExp special characters.Ensure your `react-highlight-words` version is compatible with your React version. Upgrade to v0.18.0 or higher for React 18, and v0.21.0 or higher for React 19.
Use the correct default import syntax: `import Highlighter from 'react-highlight-words';`
Set the `autoEscape` prop to `true` on the `Highlighter` component: `<Highlighter autoEscape={true} ... />`Install the package using `npm install react-highlight-words` or `yarn add react-highlight-words`. Verify the import path is exactly `react-highlight-words`.