{"id":18127213,"url":"https://github.com/dendrofen/react-search-box-hooks","last_synced_at":"2025-03-30T12:32:32.273Z","repository":{"id":66404715,"uuid":"602208641","full_name":"dendrofen/react-search-box-hooks","owner":"dendrofen","description":"React hooks for constructing search boxes with filters, using callbacks.","archived":true,"fork":false,"pushed_at":"2023-02-20T05:00:26.000Z","size":1723,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T14:49:21.840Z","etag":null,"topics":["boilerplate","chakra-ui","docker","docker-compose","react","react-api-hooks","react-filter","react-hooks","react-library","react-search","react-search-box","react-search-component","search-box"],"latest_commit_sha":null,"homepage":"https://dendrofen.github.io/react-search-box-hooks/","language":"JavaScript","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/dendrofen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-02-15T18:15:11.000Z","updated_at":"2024-10-20T20:22:35.000Z","dependencies_parsed_at":"2023-03-07T16:45:14.213Z","dependency_job_id":null,"html_url":"https://github.com/dendrofen/react-search-box-hooks","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.1428571428571429,"last_synced_commit":"fb8d006ae1241dcaa17f7f32bf6268af6788a60b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"dendrofen/docker-react-chakra-ui","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dendrofen%2Freact-search-box-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dendrofen%2Freact-search-box-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dendrofen%2Freact-search-box-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dendrofen%2Freact-search-box-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dendrofen","download_url":"https://codeload.github.com/dendrofen/react-search-box-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246319963,"owners_count":20758402,"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":["boilerplate","chakra-ui","docker","docker-compose","react","react-api-hooks","react-filter","react-hooks","react-library","react-search","react-search-box","react-search-component","search-box"],"created_at":"2024-11-01T09:15:46.144Z","updated_at":"2025-03-30T12:32:32.268Z","avatar_url":"https://github.com/dendrofen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![alt text](./readme/preview.jpg)\n\n[![Build Size](https://img.shields.io/bundlephobia/minzip/react-search-box-hooks?label=bundle%20size\u0026style=flat\u0026colorA=000000\u0026colorB=000000)](https://bundlephobia.com/result?p=react-search-box-hooks)\n[![Version](https://img.shields.io/npm/v/react-search-box-hooks?style=flat\u0026colorA=000000\u0026colorB=000000)](https://www.npmjs.com/package/react-search-box-hooks)\n[![Downloads](https://img.shields.io/npm/dt/react-search-box-hooks.svg?style=flat\u0026colorA=000000\u0026colorB=000000)](https://www.npmjs.com/package/react-search-box-hooks)\n\n# React Search Box Hooks\n\nThis library provides a set of React hooks to construct search boxes for your application.\n\n## Installation\n\nTo install the package, use:\n\n```bash\nnpm i react-search-box-hooks\n```\nor\n```bash\nyarn add react-search-box-hooks\n```\n\n## Usage\n\nThe library provides two hooks: `useSearchBox` and `useSearchBoxInput`.\n\n### useSearchBox\n\nThe `useSearchBox` hook provides a state object and an action to update the search parameters, and a method to query the data. It requires two parameters:\n\n- `queryFunc`: The function to query the data. It takes a single argument, the search parameters object, and returns a Promise that resolves to an array of search results and the total number of search results.\n- `initParams`: The initial search parameters object.\n\nThe `useSearchBox` hook returns an object with the following properties:\n\n- `items`: The array of search results.\n- `totalCount`: The total number of search results.\n- `isLoading`: A boolean value indicating whether the search is in progress.\n- `params`: The search parameters object.\n- `dispatchParams`: An action to update the search parameters.\n\n**Example of usage**\n\n```js\nfunction MyComponent() {\n  const queryFunc = useCallback((params) =\u003e {\n    const items = []\n    const totalCount = items.length\n    resolve([items, totalCount]);\n  }, []);\n\n  const { items, totalCount, isLoading, params, dispatchParams } = useSearchBox(queryFunc, { count: 0 });\n\n  const onInc = useCallback(() =\u003e {\n    dispatchParams({ key: \"count\", value: params.count + 1 });\n  }, [dispatchParams, params]);\n\n  // render the search box UI\n}\n```\n\n\u003ca href=\"https://codesandbox.io/s/react-search-box-hooks-usesearchbox-demo-twmewq?fontsize=14\u0026hidenavigation=1\u0026theme=dark\" target=\"_blank\"\u003e\n  \u003cimg alt=\"Edit react-search-box-hooks-useSearchBox-demo\" src=\"https://codesandbox.io/static/img/play-codesandbox.svg\"\u003e\n\u003c/a\u003e\n\n### useSearchBoxInput\n\nThe `useSearchBoxInput` hook provides handlers for the search box input field. It requires three parameters:\n\n- `dispatchParams`: An action to update the search parameters.\n- `paramKey`: The key of the search parameter to update.\n- `debounceTimeout`: The debounce timeout value in milliseconds.\n\nThe `useSearchBoxInput` hook returns an object with the following properties:\n\n- `ref`: A ref to the input element.\n- `onInput`: A handler for the input event.\n- `onChange`: A handler for the change event.\n- `onClear`: A handler for the clear button event.\n- `isClearable`: A boolean value indicating whether the clear button should be shown.\n\n**Example of usage**\n\n```js\nfunction MyComponent() {\n  const queryFunc = useCallback((params) =\u003e {\n    const items = Array.from(params.query || \"\");\n    return [items, items.length];\n  }, []);\n\n  const { items, totalCount, isLoading, params, dispatchParams } = useSearchBox(queryFunc, { query: 'search-box-hooks' });\n\n  const { ref, onInput, onChange, onClear, isClearable } = useSearchBoxInput( dispatchParams, \"query\" );\n\n  return (\n    \u003c\u003e\n        \u003cinput\n            defaultValue={params.query} \n            {...{ ref, onInput, onChange }}\n        /\u003e\n        {isClearable \u0026\u0026 \u003cbutton onClick={onClear}\u003eclear\u003c/button\u003e}\n\n        {/* the search box UI */}\n    \u003c/\u003e\n  )\n}\n```\n\n\u003ca href=\"https://codesandbox.io/s/react-search-box-hooks-usesearchboxinput-demo-u6ss6u?fontsize=14\u0026hidenavigation=1\u0026theme=dark\" target=\"_blank\"\u003e\n  \u003cimg alt=\"Edit react-search-box-hooks-useSearchBoxInput-demo\" src=\"https://codesandbox.io/static/img/play-codesandbox.svg\"\u003e\n\u003c/a\u003e\n\n## Contributing\n\nContributions are welcome. To contribute, fork the repository, create a branch for your changes, and submit a pull request. Please make sure that your changes are covered by tests and that the existing tests pass.\n\n## License\n\nThis library is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdendrofen%2Freact-search-box-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdendrofen%2Freact-search-box-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdendrofen%2Freact-search-box-hooks/lists"}