Fuzzy in React
Simplify your React code with these helpful fuzzy search utilities.
Summary
You can use this library in React just like in a regular JavaScript project, but we provide additional helpers to make integration easier.
The key differences are:
- Internal use of
useMemo
anduseCallback
for memoization - A more intuitive
API
designed specifically for React
The main concepts are useFuzzy
and Highlight
.
Basic Example
With just a few lines of code, you can implement fuzzy search that returns matched results and highlights matching characters:
Why we import from `/react`?
API
useFuzzy
This is the main hook, providing a performance-optimized way to search through items.
It accepts the same props as the fuzzy
function, plus some additional options:
- list - The list of items to search through. Required.
- query - The query to search for. Required.
fuzzy
function and then call it with the query. You can just use useFuzzy
and it will do it for you internally.All useFuzzy
Options
Highlight
This is a helper component that will highlight the matching characters in the text.
You could perfectly recreate this component yourself, but it's provided for convenience.
Reference
Prop | Type | Default |
---|---|---|
text | string | "" |
ranges | HighlightRanges | null |
style? | CSSProperties | { backgroundColor: "rgba(245,220,0,.25)" } |
className? | string | "" |
Examples
Static strings list
Strings search from input
Object search by one key
Objects search by multiple keys
Last updated on