{"id":21564659,"url":"https://github.com/zestgeek/on-outside-click-hook","last_synced_at":"2025-10-13T12:37:28.774Z","repository":{"id":57314426,"uuid":"170382145","full_name":"zestgeek/on-outside-click-hook","owner":"zestgeek","description":"A React custom hook to detect clicks which triggers outside the element and then fire an event.","archived":false,"fork":false,"pushed_at":"2020-04-05T12:34:34.000Z","size":26,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-11T15:57:41.226Z","etag":null,"topics":["hooks","hooks-api-react","javascript","outsideclick","react","reactjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/on-outside-click-hook","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/zestgeek.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-02-12T19:57:58.000Z","updated_at":"2024-05-27T16:46:34.000Z","dependencies_parsed_at":"2022-09-20T23:21:23.704Z","dependency_job_id":null,"html_url":"https://github.com/zestgeek/on-outside-click-hook","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zestgeek/on-outside-click-hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zestgeek%2Fon-outside-click-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zestgeek%2Fon-outside-click-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zestgeek%2Fon-outside-click-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zestgeek%2Fon-outside-click-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zestgeek","download_url":"https://codeload.github.com/zestgeek/on-outside-click-hook/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zestgeek%2Fon-outside-click-hook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015057,"owners_count":26085643,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hooks","hooks-api-react","javascript","outsideclick","react","reactjs"],"created_at":"2024-11-24T10:16:48.164Z","updated_at":"2025-10-13T12:37:28.752Z","avatar_url":"https://github.com/zestgeek.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"on-outside-click-hook\n======\nA React custom hook to detect clicks which triggers outside the element and then fire an event.\n\n\u003e Make sure your `react` and `react-dom` version is `16.8.1` or higher. Internally `on-outside-click-hook` uses react hooks which is only supported after version `16.8.1` of `react`\n\n## How to install\n```\n$ yarn add on-outside-click-hook\n```\n\n## Usage\n```javascript\nimport useOnOutsideClick from 'on-outside-click-hook'\n\nconst CustomComponent = () =\u003e {\n    const elementInstance = useOnOutsideClick(() =\u003e alert('hello'))\n    return \u003cdiv ref={elementInstance}\u003e\n        \u003ch1\u003eHello\u003c/h1\u003e\n    \u003c/div\u003e\n} \n```\n\nuseOnOutsideClick(func:function)\n-----------------------\n#### Fires passed function when click event triggers outside the target element\nWhen we will use `useOnOutsideClick` in our functional components we have to pass it a function which will be called when click event triggers outside the target element. for e.g `useOnOutsideClick(() =\u003e alert('hello'))`\n\nAlso note when we call `useOnOutsideClick` it returns an `elementInstance` which is basically a `ref` which will be passed to the `target` element as a ref. This is how `useOnOutsideClick` tracks when the click event happens outside the element.\n\n```javascript\nimport useOnOutsideClick from 'on-outside-click-hook'\n\nconst CustomComponent = () =\u003e {\n    const elementInstance = useOnOutsideClick(() =\u003e alert('hello'))\n    // elementInstance will be passed to div as a ref\n    return \u003cdiv ref={elementInstance}\u003e\n        \u003ch1\u003eHello\u003c/h1\u003e\n    \u003c/div\u003e\n} \n```\n\n### Contributers\n[\u003cimg src=\"http://zestgeek.com/wp-content/uploads/Zestgeek-new-logo-2.png\" alt=\"zestgeek solutions\" width=\"200\"/\u003e](http://zestgeek.com)\n\n[\u003cimg src=\"http://www.recraftstudio.com/images/logo.png\" alt=\"drawing\" width=\"50\"/\u003e](http://www.recraftrelic.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzestgeek%2Fon-outside-click-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzestgeek%2Fon-outside-click-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzestgeek%2Fon-outside-click-hook/lists"}