
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
react-lunr
Advanced tools
React hook to search a Lunr index.
npm install --save react-lunr
useLunr
useLunr(query?: string | lunr.Index.QueryBuilder, index?: lunr.Index | JSON | string, store: object | string) => object[]
The useLunr
hook takes your search query, index, and store and
returns results as an array. Searches are memoized to ensure efficient
searching.
Name | Type | Description |
---|---|---|
query | string | lunr.Index.QueryBuilder | The search query. As this value updates, the return value will be updated. This can be a string or a query builder. |
index | lunr.Index | JSON | string | The Lunr index. This can be an instance of a Lunr index or one that has been exported via index.toJSON or JSON.stringify . |
store | JSON | string | Object mapping a result ref to an object of data. This can be an object or an object that has been exported via JSON.stringified . |
If store
is not provided, the raw results data from Lunr will be returned
instead. This includes the ref
used when creating the index.
The following example renders a text input and queries the Lunr index on form submission.
Note: Formik is used in the following example to handle form state, but is not required. As long as your query is passed as the first parameter, you can manage how to store it.
import React, { useState } from 'react'
import { useLunr } from 'react-lunr'
import { Formik, Form, Field } from 'formik'
const index = /* a lunr index */
const store = {
1: { id: 1, title: 'Document 1' },
2: { id: 2, title: 'Document 2' },
3: { id: 3, title: 'Document 3' },
}
const SearchBar = () => {
const [query, setQuery] = useState(null)
const results = useLunr(query, index, store)
return (
<Formik
initialValues={{ query: '' }}
onSubmit={(values, { setSubmitting }) => {
setQuery(values.query)
setSubmitting(false)
}}
>
<Form>
<Field name="query" />
</Form>
<h1>Results</h1>
<ul>
{results.map(result => (
<li key={result.id}>{result.title}</li>
))}
</ul>
</Formik>
)
}
FAQs
React component to search a Lunr index
The npm package react-lunr receives a total of 914 weekly downloads. As such, react-lunr popularity was classified as not popular.
We found that react-lunr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.