{"id":18250681,"url":"https://github.com/jakex7/react-native-click-outside","last_synced_at":"2025-04-04T16:31:37.145Z","repository":{"id":65676867,"uuid":"597119882","full_name":"jakex7/react-native-click-outside","owner":"jakex7","description":"React Native library to detect clicks outside the component 👆","archived":false,"fork":false,"pushed_at":"2023-10-17T00:31:29.000Z","size":438,"stargazers_count":70,"open_issues_count":5,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-20T15:12:38.517Z","etag":null,"topics":["click-outside","hacktoberfest","open-source","react-native"],"latest_commit_sha":null,"homepage":"","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/jakex7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-03T17:11:54.000Z","updated_at":"2025-02-19T21:48:13.000Z","dependencies_parsed_at":"2023-10-17T06:02:08.873Z","dependency_job_id":"74803c9d-9690-4456-99fa-3de5f5b8eb20","html_url":"https://github.com/jakex7/react-native-click-outside","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"fcbbb2a731b38439b3a37c5463200f1fb4d92c78"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakex7%2Freact-native-click-outside","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakex7%2Freact-native-click-outside/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakex7%2Freact-native-click-outside/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakex7%2Freact-native-click-outside/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakex7","download_url":"https://codeload.github.com/jakex7/react-native-click-outside/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247123099,"owners_count":20887261,"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":["click-outside","hacktoberfest","open-source","react-native"],"created_at":"2024-11-05T09:45:34.564Z","updated_at":"2025-04-04T16:31:36.674Z","avatar_url":"https://github.com/jakex7.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-click-outside\n\nReact Native library to detect clicks outside the component 👆\n\n\n![Build status - typescript compile](https://img.shields.io/github/actions/workflow/status/jakex7/react-native-click-outside/ci.yml?branch=main)\n![License badge](https://img.shields.io/npm/l/react-native-click-outside)\n![Latest, released version](https://img.shields.io/github/v/release/jakex7/react-native-click-outside)\n![Date of latest commit](https://img.shields.io/github/last-commit/jakex7/react-native-click-outside)\n\n\n## 🪄 Installation\n\n```sh\nyarn add react-native-click-outside\n```\n\n## 📖 Usage\n\nFirst of all, you need to wrap your app with `ClickOutsideProvider` as high as possible, for example in `App.tsx`:\n\n```tsx\nimport { ClickOutsideProvider } from 'react-native-click-outside';\n\nexport const App = () =\u003e (\n  \u003cClickOutsideProvider\u003e\n    { /* rest of your app */ }\n  \u003c/ClickOutsideProvider\u003e\n);\n```\n\nThen you can call `useClickOutside` hook to detect clicks outside the component. First argument is the function that will be called every time user clicks outside of this component. It returns `ref` that you need to attach to the component you want to detect clicks outside of. For example:\n\n```tsx\nimport { useClickOutside } from 'react-native-click-outside';\n\nexport default function MyComponent() {\n  const ref = useClickOutside\u003cView\u003e(() =\u003e console.log('clicked outside A'));\n  return (\n    \u003cView ref={ref}\u003e\n      \u003cText\u003eTest\u003c/Text\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n## 🛠️ Troubleshooting\n\n### iOS works fine, but Android doesn't\nAs stated in react-native docs, on Android\n\n\u003e Views that are only used to layout their children or otherwise don't draw anything may be automatically removed from the native hierarchy as an optimization.\n\n_Source: https://reactnative.dev/docs/view#collapsable-android_\n\nIf your element is collapsable, it won't be rendered, and therefore you won't be able to detect clicks outside of it.\nTo prevent this, you need to add `collapsable={false}` prop to the component. For example:\n\n```tsx\nconst ref = useClickOutside\u003cView\u003e(() =\u003e console.log('clicked outside'));\n\u003cView collapsable={false} ref={ref}\u003e\n  \u003cText\u003eTest\u003c/Text\u003e\n\u003c/View\u003e\n```\n\n## ⚖️ License\n\n**[MIT](/LICENSE)**\n\n## 📝 Contribute\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n\n### Built with ♥️ by Jakub Grzywacz\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakex7%2Freact-native-click-outside","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakex7%2Freact-native-click-outside","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakex7%2Freact-native-click-outside/lists"}