{"id":13725311,"url":"https://github.com/angeloashmore/react-use-flexsearch","last_synced_at":"2025-04-09T22:16:26.935Z","repository":{"id":34311722,"uuid":"177234568","full_name":"angeloashmore/react-use-flexsearch","owner":"angeloashmore","description":"React hook to search a FlexSearch index","archived":false,"fork":false,"pushed_at":"2023-01-03T18:21:36.000Z","size":1806,"stargazers_count":103,"open_issues_count":27,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T22:16:21.871Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/angeloashmore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-23T02:26:49.000Z","updated_at":"2025-02-11T10:48:17.000Z","dependencies_parsed_at":"2023-01-15T06:30:38.303Z","dependency_job_id":null,"html_url":"https://github.com/angeloashmore/react-use-flexsearch","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeloashmore%2Freact-use-flexsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeloashmore%2Freact-use-flexsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeloashmore%2Freact-use-flexsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeloashmore%2Freact-use-flexsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angeloashmore","download_url":"https://codeload.github.com/angeloashmore/react-use-flexsearch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119287,"owners_count":21050755,"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":[],"created_at":"2024-08-03T01:02:19.133Z","updated_at":"2025-04-09T22:16:26.909Z","avatar_url":"https://github.com/angeloashmore.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# react-use-flexsearch\n\nReact hook to search a [FlexSearch][flexsearch] index.\n\n## Status\n\n[![npm version](https://badge.fury.io/js/react-use-flexsearch.svg)](http://badge.fury.io/js/react-use-flexsearch)\n\n## Installation\n\n```sh\nnpm install --save react-use-flexsearch\n```\n\n## API\n\n```js\nuseFlexSearch(query: String, index: Index | String, store: Object, options: Object) =\u003e Object[]\n```\n\nThe `useFlexSearch` [hook][hooks] takes your search query, index, and store and\nreturns results as an array. Searches are memoized to ensure efficient\nsearching.\n\n### Parameters\n\n| Name          | Type              | Description                                                                                                           |\n| ------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------- |\n| **`query`**   | `String`          | The search query. As this value updates, the return value will be updated.                                            |\n| **`index`**   | `Index \\| String` | The FlexSearch index. This can be an instance of a FlexSearch index or one that has been exported via `Index.export`. |\n| **`store`**   | `Object`          | Object mapping a result `id` to an object of data.                                                                    |\n| **`options`** | `Object`          | Search options passed to `Index.search`.                                                                              |\n\n### Example\n\nThe following example renders a text input and queries the FlexSearch index on\nform submission.\n\nNote: [Formik][formik] is used in the following example to handle form state,\nbut is not required. As long as your query is passed as the first parameter, you\ncan manage how to store it.\n\n```jsx\nimport React, { useState } from 'react'\nimport { useFlexSearch } from 'react-use-flexsearch'\nimport { Formik, Form, Field } from 'formik'\n\nconst index = /* a FlexSearch index */\nconst store = {\n  1: { id: 1, title: 'Document 1' },\n  2: { id: 2, title: 'Document 2' },\n  3: { id: 3, title: 'Document 3' },\n}\n\nconst SearchBar = () =\u003e {\n  const [query, setQuery] = useState(null)\n  const results = useFlexSearch(query, index, store)\n\n  return (\n    \u003cdiv\u003e\n      \u003cFormik\n        initialValues={{ query: '' }}\n        onSubmit={(values, { setSubmitting }) =\u003e {\n          setQuery(values.query)\n          setSubmitting(false)\n        }}\n      \u003e\n        \u003cForm\u003e\n          \u003cField name=\"query\" /\u003e\n        \u003c/Form\u003e\n      \u003c/Formik\u003e\n      \u003ch1\u003eResults\u003c/h1\u003e\n      \u003cul\u003e\n        {results.map(result =\u003e (\n          \u003cli key={result.id}\u003e{result.title}\u003c/li\u003e\n        ))}\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n[flexsearch]: https://github.com/nextapps-de/flexsearch\n[hooks]: https://reactjs.org/docs/hooks-intro.html\n[formik]: https://github.com/jaredpalmer/formik\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangeloashmore%2Freact-use-flexsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangeloashmore%2Freact-use-flexsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangeloashmore%2Freact-use-flexsearch/lists"}