{"id":19451236,"url":"https://github.com/thekashey/react-event-injector","last_synced_at":"2025-04-25T04:30:23.617Z","repository":{"id":65412041,"uuid":"153091780","full_name":"theKashey/react-event-injector","owner":"theKashey","description":"💉React way to addEventListener","archived":false,"fork":false,"pushed_at":"2018-10-18T09:49:45.000Z","size":356,"stargazers_count":47,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T15:47:05.712Z","etag":null,"topics":["event-management","optimization","react"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/theKashey.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":"2018-10-15T10:04:27.000Z","updated_at":"2025-01-16T17:58:20.000Z","dependencies_parsed_at":"2023-01-23T10:55:01.580Z","dependency_job_id":null,"html_url":"https://github.com/theKashey/react-event-injector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theKashey%2Freact-event-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theKashey%2Freact-event-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theKashey%2Freact-event-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theKashey%2Freact-event-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theKashey","download_url":"https://codeload.github.com/theKashey/react-event-injector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250754501,"owners_count":21481823,"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":["event-management","optimization","react"],"created_at":"2024-11-10T16:40:50.427Z","updated_at":"2025-04-25T04:30:23.211Z","avatar_url":"https://github.com/theKashey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e💉 React-Event-Injector‍\u003c/h1\u003e\n  \u003cbr/\u003e\n  \u003ca href=\"https://secure.travis-ci.org/theKashey/react-event-injector\"\u003e\n     \u003cimg src=\"https://secure.travis-ci.org/theKashey/react-event-injector.svg\" alt=\"Build status\"\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://www.npmjs.com/package/react-event-injector\"\u003e\n   \u003cimg src=\"https://img.shields.io/npm/v/react-event-injector.svg?style=flat-square\" /\u003e\n  \u003c/a\u003e\n  \n  \u003cbr/\u003e  \n\u003c/div\u003e  \n\n-----\nDeclarative React event manager, slim as 1kb. \nUses _standard_ addEventListener underneath, and able to overtake current [React API Limitations](https://github.com/facebook/react/issues/6436).\n\nPlease - don't overuse this library, as long \"React\" way to attach events is\nfar more performant, and better working with React itself. \n\n# API\nThere is 3 Components, exported from this package\n- `EventInjector` - to inject events somewhere down the tree\n- `PassiveListener` - to inject \"passive\" events, which could be quite useful to make application run smoothly. \n- `ActiveListener` - to inject __non__ \"passive\" events, as long some events are passive by default.\n- `TargetedInjector` - to inject events to the specific target.\n\nAll components will add events on `mount`, remove on `unmount`, and update changed on `update` if `pure` is not set.\n\n# Why\n- 😀 to inject passive events. There is no way to inject them in \"react-way\".\n- 😀 to inject events where you need, without relaying on bubbling or capturing or some react details.\n- ☹️ to get native DOM event, not React.Synthetic.\n- ☹️ to work with DOM Tree, not React.Tree.\n\n## Injection API\n\n### Children as React Element\n- You may provide a single __tag__, as a children, or use `forwardRef` to forward ref to the proper target.\n```js\nimport {EventInjector} from 'react-event-injector';\n\u003cEventInjector onClick={event}\u003e\n \u003cdiv\u003eIt will inject onClick on me, please pass a SINGLE and HTML tag inside injector\u003c/div\u003e\n\u003c/EventInjector\u003e \n```\n\n- Capture events are also supported\n```js\nimport {EventInjector} from 'react-event-injector';\n\u003cEventInjector \n    onClick={event}\n    // capture events are also supported\n    onKeydownCapture={event} \n    // explicity set passive:false to all events. Better set to true\n    settings={{passive:false}}\n\u003e\n \u003cdiv\u003eIt will inject onClick on me, please pass a SINGLE and HTML tag inside injector\u003c/div\u003e\n\u003c/EventInjector\u003e \n```\n- You may nest Injectors one inside another. Injectors __is the only way__ to combine,\n`passive`, `active`, and `neutral` event listeners.\n\u003e All injectors implements EventTarget interface, and could be `ref`-ed by another injectors.\n```js\nimport {PassiveListener, EventInjector} from 'react-event-injector';\n\u003cPassiveListener onScroll={event}\u003e\n  \u003cEventInjector onClick={event}\u003e\n    \u003cEventInjector onKeydownCapture={event}\u003e\n      \u003cdiv\u003eIt will inject onClick on me, please pass a SINGLE and HTML tag inside injector\u003c/div\u003e\n    \u003c/EventInjector\u003e\n  \u003c/EventInjector\u003e  \n\u003c/PassiveListener\u003e\n```\n\n### Children as RenderProp\nYou may provide a single __tag__, as a children, or use `forwardRef` to forward ref to the proper target.\n```js\nimport {EventInjector} from 'react-event-injector';\n\u003cEventInjector onClick={event}\u003e\n { setRef =\u003e (\n \u003cdiv ref={setRef}\u003e\n   It will inject onClick on me\u003c/div\u003e\n }  \n\u003c/EventInjector\u003e \n```\n\n`EventInjector`, `ActiveListener` and `PassiveListener` has the same API, and accept only `children` and any on-`event`, or on-`event`-Capture, as any HTML tag does.\nThe difference is default value for `settings`. \n\n## TargetedInjector\n- Inject events to any `target` provided:\n```js\nimport {TargetedInjector} from 'react-event-injector';\n\u003cTargetedInjector \nonClick={event}\ntarget={this.ref}\n\u003e  \n``` \n- You may use function as a target\n```js\nimport {TargetedInjector} from 'react-event-injector';\n\u003cTargetedInjector \nonClick={event}\ntarget={() =\u003e document.querySelector('#element-i-need')}\n\u003e  \n``` \nIn the case of a function, `target` would be executed twice - on componentDidMount, and right after it,\n thus it will be able to inject events to sibling elements, not existing on mount.\n\n\n\n# Inspiration\n- `TargetedInjector` is quite similar to [react-event-listener](https://github.com/oliviertassinari/react-event-listener).\n- `PassiveListener` is quite similar to [default-passive-events](https://github.com/zzarcon/default-passive-events)\n\n# Licence\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekashey%2Freact-event-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthekashey%2Freact-event-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekashey%2Freact-event-injector/lists"}