{"id":16822228,"url":"https://github.com/strml/react-document-events","last_synced_at":"2025-09-22T02:33:17.328Z","repository":{"id":42927848,"uuid":"54421213","full_name":"STRML/react-document-events","owner":"STRML","description":"Declarative method for binding handlers to document and window - and cleaning them up.","archived":false,"fork":false,"pushed_at":"2023-03-04T06:06:43.000Z","size":612,"stargazers_count":24,"open_issues_count":5,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-10T04:55:09.106Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/STRML.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-03-21T20:42:30.000Z","updated_at":"2024-08-12T19:22:01.000Z","dependencies_parsed_at":"2024-06-18T18:35:51.664Z","dependency_job_id":"094eafd9-989c-44b2-9860-b7c5ac3dcf05","html_url":"https://github.com/STRML/react-document-events","commit_stats":{"total_commits":38,"total_committers":3,"mean_commits":"12.666666666666666","dds":0.3157894736842105,"last_synced_commit":"8458e04aaddd35b498ece0227ef528ad35507621"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Freact-document-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Freact-document-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Freact-document-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Freact-document-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/STRML","download_url":"https://codeload.github.com/STRML/react-document-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233819586,"owners_count":18735302,"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-13T11:02:49.266Z","updated_at":"2025-09-22T02:33:12.066Z","avatar_url":"https://github.com/STRML.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-document-events\n\nDeclarative method for binding handlers to document and window - and cleaning them up.\n\n### Usage\n\nGiven an imaginary component that listens to the 'esc' key, but only if its\nparent tells it to:\n\n```js\nimport React from 'react';\nimport DocumentEvents from 'react-document-events';\n\nclass SideEffectingComponent extends React.Component {\n\n  onKeyUp = (e) =\u003e {\n    if (e.keyCode === 27 /* esc */) this.toggleSomethingOnEsc(e);\n  };\n\n  render() {\n    var target = process.browser ? document : null;\n    return (\n      \u003cdiv\u003e\n        \u003cdiv\u003eComponent Innards\u003c/div\u003e\n        \u003cDocumentEvents enabled={this.props.listenToKeys} onKeyUp={this.onKeyUp} passive={false} capture={false} /\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n```\n\n#### Props\n\n* **capture** (`boolean=false`): If true, will add listeners in the `capture` phase.\n* **enabled** (`boolean=true`): If true, will attach handlers, if false, will remove them. Safe to add/remove at will.\n* **passive** (`boolean=false`): If true, will add listeners with the\n  [passive option](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners),\n  if supported. A feature test is performed to ensure this does not accidentally set `useCapture`.\n* **target** (`(HTMLElement | () =\u003e HTMLElement | () =\u003e void | void)=document`): The element to attach listeners to.\n  May also be a function returning said element. If void, or returning void, this element will noop.\n  * To be safe when server rendering, the default is `document`, but only if `process.browser` returns true.\n* **on[eventName]** (`EventHandler`): Any valid [event handler name](https://facebook.github.io/react/docs/events.html).\n  Note these events are attached directly, so you will receive browser events, not React's `SyntheticEvent`, although the semantics are mostly the same.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Freact-document-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrml%2Freact-document-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Freact-document-events/lists"}