A tiny wrapper around the Fuse.js fuzzy-search library using React Hooks.
npm install use-fuseA tiny wrapper around the Fuse.js fuzzy-search library using React Hooks.
bash
npm install use-fuse --save
`
or Yarn:
`bash
yarn add use-fuse --save
`
Usage
The library exports a single hook.
Example
`jsx
import React from 'react'
import useFuse from 'use-fuse'
// see: https://fusejs.io/
const fuseOptions = {
keys: ['name'],
threshold: 0.6,
}
function App() {
const [list] = React.useState([
{ name: 'Hesse' },
{ name: 'Pelevin' },
{ name: 'Steinbeck' },
{ name: 'Moore' },
{ name: 'Atwood' },
])
const [search] = React.useState('')
const filteredList = useFuse(list, search, fuseOptions)
return (
{filteredList.map(item => (
- {item.name}
))}
)
}
`
Parameters
`js
useFuse(list, searchTerm, fuseOptions) : filteredList
``