Skip to content

A tiny wrapper for the fuzzy-search library Fuse.js using React Hooks

License

Notifications You must be signed in to change notification settings

sforsberg/react-use-fuse

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-use-fuse

A tiny wrapper for the fuzzy-search library Fuse.js using React Hooks.

Example usage

const customers = [
    {id: 1, name: 'Customer A', email: '[email protected]'},
    {id: 2, name: 'Customer B' email: '[email protected]'}
]

function MyComponent({customers}){

    // This is Fuse specific options. Read more at
    // https://fusejs.io/#examples
    const options = {
        keys: ["name", "email"]
    }

    // Setup the Hook.
    const { result, search, term, reset } = useFuse({
        data: customers,
        options
    });

    return (
        <div>
            <input
                onChange={e => search(e.target.value)}
                value={term}
                placeholder="Search for a customer..."
            />

            {result.map(customer => (
                <div>
                    {customer.name} - {customer.email}
                </div>
            ))}
        </div>
    )
}

<MyComponent customers={customers} />

About

A tiny wrapper for the fuzzy-search library Fuse.js using React Hooks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%