
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
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 782 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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.