{"id":17181534,"url":"https://github.com/dimitarchristoff/react-outerclick","last_synced_at":"2025-04-13T17:50:25.423Z","repository":{"id":57342130,"uuid":"72552399","full_name":"DimitarChristoff/react-outerclick","owner":"DimitarChristoff","description":"HOC wrapper for React Components (class) to handle outside clicks with a frugal document event strategy.","archived":false,"fork":false,"pushed_at":"2018-09-17T14:03:11.000Z","size":505,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T21:05:23.979Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://dimitarchristoff.github.io/react-outerclick/","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/DimitarChristoff.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":"2016-11-01T16:01:17.000Z","updated_at":"2018-09-17T14:03:03.000Z","dependencies_parsed_at":"2022-09-16T02:50:44.309Z","dependency_job_id":null,"html_url":"https://github.com/DimitarChristoff/react-outerclick","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimitarChristoff%2Freact-outerclick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimitarChristoff%2Freact-outerclick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimitarChristoff%2Freact-outerclick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimitarChristoff%2Freact-outerclick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DimitarChristoff","download_url":"https://codeload.github.com/DimitarChristoff/react-outerclick/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248758002,"owners_count":21156955,"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-10-15T00:34:35.922Z","updated_at":"2025-04-13T17:50:25.394Z","avatar_url":"https://github.com/DimitarChristoff.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-outerclick\n\nHOC wrapper with frugal document event strategy\n\n\u003e NB: this will work with React Classes, not with stateless components\n\nGet a callback when a click happens outside of your component. If your React class implements `handleOuterClick`, it will get called when a click outside of the root node for your element takes place.\n\n## Installation\n\n```bash\nnpm i react-outerclick\n```\n\n## Usage\n\nAs a HOC, you can use the experimental decorator style:\n\n```js\nimport React from 'react';\nimport outerClick from 'react-outerclick';\n\n@outerClick\nclass Foo extends React.Component {\n\n  state = {\n    opened: true\n  };\n\n  handleOuterClick(event){\n    this.setState({\n        opened: false\n    });\n  }\n\n  render(){\n    return \u003cdiv\u003eFoo. Click elsewhere\u003c/div\u003e;\n  }\n}\n\nexport default Foo;\n```\n\nAlternatively, without `stage-0` and `babel-plugin-transform-decorators-legacy`, this looks like so:\n\n```js\nimport React from 'react';\nimport outerClick from 'react-outerclick';\n\nclass Foo extends React.Component {\n\n  constructor(props){\n    super(props);\n    this.state = {\n        opened: true\n    };\n  }\n\n  handleOuterClick(event){\n    this.setState({\n        opened: false\n    });\n  }\n\n  render(){\n    return \u003cdiv\u003eFoo. Click elsewhere\u003c/div\u003e;\n  }\n}\n\n// decorate here:\nexport default outerClick(Foo);\n```\n\n## Why?\n\nBecause:\n\n - need to be able to do this with a low footprint - so a single document event handler for all elements that need it.\n - gets `element.ownerDocument` correctly so can work in popups/tearoffs, unlike other implementations\n\n## Limitations\n\nHot Module Reloading (react-hmre, react-hot-loader etc) any component that has an outerClick handler will cause the outer click functionality to fail as it's not going to find the old component instance and there is no lifecycle method that is available to refresh the event subscriptions.\n\n## Found an issue, or want to contribute?\n\nIf you find an issue, want to start a discussion on something related to this project, or have suggestions on how to improve it? Please [create an issue](../../issues/new)!\n\nSee an error and want to fix it? Want to add a file or otherwise make some changes? All contributions are welcome!\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimitarchristoff%2Freact-outerclick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimitarchristoff%2Freact-outerclick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimitarchristoff%2Freact-outerclick/lists"}