{"id":16732679,"url":"https://github.com/lucaong/react-minisearch","last_synced_at":"2025-04-04T20:08:44.603Z","repository":{"id":35113353,"uuid":"208335362","full_name":"lucaong/react-minisearch","owner":"lucaong","description":"React integration for the MiniSearch client side full-text search library","archived":false,"fork":false,"pushed_at":"2024-12-16T12:15:07.000Z","size":1463,"stargazers_count":50,"open_issues_count":4,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T00:09:04.530Z","etag":null,"topics":["autocomplete","autosuggestion","full-text","minisearch","react","search","search-engine"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucaong.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-13T19:46:24.000Z","updated_at":"2025-02-06T08:58:11.000Z","dependencies_parsed_at":"2024-06-18T22:37:09.692Z","dependency_job_id":"8eba9b33-250b-4a2e-98b2-4fa6992fc4b1","html_url":"https://github.com/lucaong/react-minisearch","commit_stats":{"total_commits":165,"total_committers":7,"mean_commits":"23.571428571428573","dds":"0.12121212121212122","last_synced_commit":"f71530b40089369d63af1b43140345d648194a9f"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaong%2Freact-minisearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaong%2Freact-minisearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaong%2Freact-minisearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaong%2Freact-minisearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucaong","download_url":"https://codeload.github.com/lucaong/react-minisearch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242678,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autocomplete","autosuggestion","full-text","minisearch","react","search","search-engine"],"created_at":"2024-10-12T23:46:11.267Z","updated_at":"2025-04-04T20:08:44.579Z","avatar_url":"https://github.com/lucaong.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React MiniSearch\n\nReact integration for the [MiniSearch](https://github.com/lucaong/minisearch) client side full-text search library.\n\n## Getting Started\n\n### Installation:\n\nFirst, make sure you have a compatible version of\n[React](https://github.com/facebook/react) and of\n[MiniSearch](https://github.com/lucaong/minisearch) installed.\n\nThen, install via **NPM** or **Yarn**:\n\n```bash\n# With NPM:\nnpm install react-minisearch\n\n# Or with Yarn:\nyarn add react-minisearch\n```\n\n### Usage:\n\nThere are three main ways to use `react-minisearch`: the `useMiniSearch` hook, the `withMiniSearch` higher-order component, or the `WithMiniSearch` wrapper component.\n\nAll three way take the following arguments (or props for the wrapper component):\n\n  - The initial collection of documents to add to the index. Note: this is just\n    the initial collection, and mutating this argument won't cause reindexing.\n    To add or remove documents after initialization, use the functions\n    `add`/`addAll`/`remove`/`removeAll`/`discard`, etc.\n  - The `MiniSearch` configuration options\n\n#### Using the useMiniSearch hook:\n\n```jsx\nimport { useMiniSearch } from 'react-minisearch'\n\n// Documents to search amongst\nconst documents = [\n  { id: 1, name: 'Agata' },\n  { id: 2, name: 'Finn' },\n  // …etc\n]\n\n// See MiniSearch for documentation on options\nconst miniSearchOptions = { fields: ['name'] }\n\nconst MyComponent = () =\u003e {\n  const { search, searchResults } = useMiniSearch(documents, miniSearchOptions)\n\n  const handleSearchChange = (event) =\u003e {\n    search(event.target.value)\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput type='text' onChange={handleSearchChange} placeholder='Search…' /\u003e\n\n      \u003col\u003e\n        \u003ch3\u003eResults:\u003c/h3\u003e\n        {\n          searchResults \u0026\u0026 searchResults.map((result, i) =\u003e {\n            return \u003cli key={i}\u003e{ result.name }\u003c/li\u003e\n          })\n        }\n      \u003c/ol\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n#### Using the withMiniSearch higher-order component:\n\n```jsx\nimport { withMiniSearch } from 'react-minisearch'\n\nconst MyComponent = ({ search, searchResults }) =\u003e {\n\n  const handleSearchChange = (event) =\u003e {\n    search(event.target.value)\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput type='text' onChange={handleSearchChange} placeholder='Search…' /\u003e\n\n      \u003col\u003e\n        \u003ch3\u003eResults:\u003c/h3\u003e\n        {\n          searchResults \u0026\u0026 searchResults.map((result, i) =\u003e {\n            return \u003cli key={i}\u003e{ result.name }\u003c/li\u003e\n          })\n        }\n      \u003c/ol\u003e\n    \u003c/div\u003e\n  )\n}\n\n// Documents to search amongst\nconst documents = [\n  { id: 1, name: 'Agata' },\n  { id: 2, name: 'Finn' },\n  // …etc\n]\n\n// See MiniSearch for documentation on options\nconst miniSearchOptions = { fields: ['name'] }\n\nconst MyComponentWithSearch = withMiniSearch(documents, miniSearchOptions, MyComponent)\n```\n\n#### Using the WithMiniSearch wrapper component:\n\n```jsx\nimport { WithMiniSearch } from 'react-minisearch'\n\n// Documents to search amongst\nconst documents = [\n  { id: 1, name: 'Agata' },\n  { id: 2, name: 'Finn' },\n  // …etc\n]\n\n// See MiniSearch for documentation on options\nconst miniSearchOptions = { fields: ['name'] }\n\nconst MyComponent = () =\u003e (\n  \u003cWithMiniSearch documents={documents} options={miniSearchOptions}\u003e\n    {\n      ({ search, searchResults }) =\u003e {\n        const handleSearchChange = (event) =\u003e {\n          search(event.target.value)\n        }\n\n        return (\n          \u003cdiv\u003e\n            \u003cinput type='text' onChange={handleSearchChange} placeholder='Search…' /\u003e\n\n            \u003col\u003e\n              \u003ch3\u003eResults:\u003c/h3\u003e\n              {\n                searchResults \u0026\u0026 searchResults.map((result, i) =\u003e {\n                  return \u003cli key={i}\u003e{ result.name }\u003c/li\u003e\n                })\n              }\n            \u003c/ol\u003e\n          \u003c/div\u003e\n        )\n      }\n    }\n  \u003c/WithMiniSearch\u003e\n)\n```\n\n### Provided props:\n\nThe complete set of props that are provided by `react-minisearch` is the same\nfor all three ways (`useMiniSearch`, `withMiniSearch`, or `WithMiniSearch`):\n\n  - `search(query: string, searchOptions?: SearchOptions) =\u003e void`: function to\n    be called in order to perform the search\n\n  - `searchResults: T[] | null`: array of search results, or `null` when no\n    search was performed or search was cleared\n\n  - `rawResults: SearchResult[] | null`: array of raw search results from\n    MiniSearch, including scores and match information, or `null` when no search\n    was performed or search was cleared\n\n  - `clearSearch() =\u003e void`: function to be called in order to clear the search\n    (setting `searchResults` to `null`)\n\n  - `autoSuggest(query: string, searchOptions?: SearchOptions) =\u003e void`:\n    function to be called in order to obtain auto suggestions\n\n  - `suggestions: Suggestion[] | null`: array of auto suggestions, or `null`\n    when auto suggestions are not used or cleared\n\n  - `clearSuggestions() =\u003e void`: function to be called in order to clear the\n    suggestions (setting `suggestions` to `null`)\n\n  - `add(document: T) =\u003e void`: function to add a new document to the index\n\n  - `addAll(documents: T[]) =\u003e void`: function to add several new documents to\n    the index in bulk\n\n  - `addAllAsync(documents: T[], options?: object) =\u003e Promise\u003cvoid\u003e`: same as\n    `addAll`, but works asynchronously and in batches to avoid blocking the UI\n\n  - `getById(id: any) =\u003e T | null`: function to retrieve a document from the index\n    by its ID\n\n  - `remove(document: T) =\u003e void`: function to remove a document from the index\n\n  - `removeById(id: any) =\u003e void`: function to remove a document from the index\n    by its ID\n\n  - `removeAll(documents?: T[]) =\u003e void`: function to remove several documents,\n    or all documents, from the index\n\n  - `discard(id: any) =\u003e void`: discard a document by its ID (same as\n    `removeById`)\n\n  - `discardAll(ids: readonly any[]) =\u003e void`: discard several documents at\n    once, by their ID\n\n  - `replace(document: T) =\u003e void`: replace an existing document with a new\n    version of it\n\n  - `isIndexing: boolean`: set to `true` when indexing via `addAllAsync` is in\n    progress, `false` otherwise\n\n  - `miniSearch: MiniSearch`: the `MiniSearch` instance, for the (rare) cases\n    when it is necessary to use it directly\n\nIn this list, the type `T` is a generic type that refers to the type of the document being indexed.\n\nMany of these props correspond to methods on the `MiniSearch` class, as\ndocumented in the [MiniSearch\nlibrary](https://github.com/lucaong/minisearch).\n\n\n## Examples\n\nCheck out the `examples` directory for a complete usage example. To run the\nexample app locally:\n\n  - `cd` to the `examples` directory\n  - Install dependencies with `yarn install` (or `npm install`)\n  - Run the example application with `yarn start` (or `npm run start`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucaong%2Freact-minisearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucaong%2Freact-minisearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucaong%2Freact-minisearch/lists"}