Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-highlight-words

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-highlight-words

React component to highlight words within a larger body of text

  • 0.20.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
502K
increased by6.1%
Maintainers
3
Weekly downloads
 
Created

What is react-highlight-words?

The react-highlight-words package is a React component used to highlight words within a larger body of text. It is useful for search results, text highlighting, and other applications where specific words or phrases need to be visually emphasized.

What are react-highlight-words's main functionalities?

Basic Highlighting

This feature allows you to highlight specific words within a text. The `searchWords` array contains the words to be highlighted, and the `textToHighlight` is the text where the words will be highlighted.

import React from 'react';
import Highlighter from 'react-highlight-words';

const text = 'This is a sample text to demonstrate highlighting.';
const searchWords = ['sample', 'highlighting'];

const App = () => (
  <Highlighter
    highlightClassName="YourHighlightClass"
    searchWords={searchWords}
    autoEscape={true}
    textToHighlight={text}
  />
);

export default App;

Custom Highlighting Styles

This feature allows you to apply custom styles to the highlighted words. The `highlightStyle` prop is used to define the CSS styles for the highlighted text.

import React from 'react';
import Highlighter from 'react-highlight-words';

const text = 'This is a sample text to demonstrate custom highlighting.';
const searchWords = ['sample', 'custom'];

const App = () => (
  <Highlighter
    highlightStyle={{ backgroundColor: 'yellow', fontWeight: 'bold' }}
    searchWords={searchWords}
    autoEscape={true}
    textToHighlight={text}
  />
);

export default App;

Case Insensitive Highlighting

This feature allows you to perform case insensitive highlighting. By setting the `caseSensitive` prop to `false`, the component will highlight words regardless of their case.

import React from 'react';
import Highlighter from 'react-highlight-words';

const text = 'This is a Sample text to demonstrate case insensitive highlighting.';
const searchWords = ['sample', 'highlighting'];

const App = () => (
  <Highlighter
    highlightClassName="YourHighlightClass"
    searchWords={searchWords}
    autoEscape={true}
    caseSensitive={false}
    textToHighlight={text}
  />
);

export default App;

Other packages similar to react-highlight-words

Keywords

FAQs

Package last updated on 22 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc