{"id":13450672,"url":"https://github.com/geobde/use-click-away","last_synced_at":"2025-03-23T16:31:53.166Z","repository":{"id":57387916,"uuid":"273801763","full_name":"geobde/use-click-away","owner":"geobde","description":"React hook to detect click or touch events outside an element.","archived":false,"fork":false,"pushed_at":"2024-10-26T22:42:29.000Z","size":1425,"stargazers_count":78,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-27T19:26:42.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/use-click-away?activeTab=readme","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/geobde.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-06-20T23:40:49.000Z","updated_at":"2024-10-26T22:42:26.000Z","dependencies_parsed_at":"2024-01-07T00:05:12.851Z","dependency_job_id":"cfda4d6c-fa6d-4406-b92e-8b36fae158d7","html_url":"https://github.com/geobde/use-click-away","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"f711834f8d2ade15bdbeddb58248d43c62c08cf0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geobde%2Fuse-click-away","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geobde%2Fuse-click-away/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geobde%2Fuse-click-away/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geobde%2Fuse-click-away/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geobde","download_url":"https://codeload.github.com/geobde/use-click-away/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245130886,"owners_count":20565737,"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-07-31T07:00:37.192Z","updated_at":"2025-03-23T16:31:52.814Z","avatar_url":"https://github.com/geobde.png","language":"JavaScript","funding_links":[],"categories":["Packages","⚛️ React"],"sub_categories":["React-specific libs:"],"readme":"# React hook to detect click or touch events\n\n`useClickAway()` reacts to clicks outside the bound element, and calls the expression that is passed in when this event is detected.\n\nSuppose you're working on a Modal component that renders a dialog box, and you wish to close the modal if the user clicks away this is the ideal scenario for `useClickAway()` custom hook.\n\n## Installation\n\nUsing `npm`:\n\n```bash\nnpm i use-click-away --save\n```\n\n## Usage\n\nImport the hook:\n\n```javascript\nimport { useClickAway } from \"use-click-away\";\n```\n\n### Full example\n\n```\nexport default () =\u003e {\n  const [modal, setModal] = React.useState(false);\n  const clickRef = React.useRef(\"\");\n\n  useClickAway(clickRef, () =\u003e {\n    setModal(false);\n  });\n\n  return (\n    \u003cdiv className=\"container\"\u003e\n      \u003cbutton onClick={() =\u003e setModal(true)}\u003eShow Modal\u003c/button\u003e\n      {modal \u0026\u0026 \u003cdiv ref={clickRef} className=\"modal\"\u003eModal Content\u003c/div\u003e}\n    \u003c/div\u003e\n  );\n}\n\n```\n\n## Specification\n\n### `useClickAway()` input\n\n- `clickRef: element` - The dom element to bind our hook.\n- `callback: function` - The callback that runs after user click\n\n## Built With\n\n[React](https://reactjs.org/)\n\n## License\n\n[MIT](./LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeobde%2Fuse-click-away","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeobde%2Fuse-click-away","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeobde%2Fuse-click-away/lists"}