This small library is created to highlight text in react.
I just wanted to try and created a small library that I can use to highlight text while searching.
- Highlight Component
import { Highlighter } from "highlight-react-text";
const Text = () => {
return (
<Highlighter searchText="highlight">
This is the highlighted text we are looking at.
</Highlighter>
);
};
- useHighlighter custom react hook
import { Highlighter } from "highlight-react-text";
const Text = () => {
const { highlights } = useHighlighter({
searchText: "highlight",
text: "This is the highlighted text we are looking at",
});
return <p>{highlights}</p>;
};