
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
react-events-listeners
Advanced tools
(This package isn't only restricted to react-js projects. The source is written in plain js with no dependencies to react-js.)
(This package isn't only restricted to react-js projects. The source is written in plain js with no dependencies to react-js.)
In some very specific cases it can be charming to have a simple global event listener. While working with global event listeners you don't have to pass touch events through the component tree into other components or can bypass easily the redux architecture for example.
npm install --save react-events-listeners
or
yarn add react-events-listeners
Hint: The event listeners also work across different files. You only have to import the EventRegister
in every file you need to send or receive your events.
import { EventRegister } from 'react-events-listeners'
/*
* RECEIVER COMPONENT
*/
class Receiver extends PureComponent {
constructor(props) {
super(props)
this.state = {
data: 'no data',
}
}
componentWillMount() {
this.listener = EventRegister.addEventListener('myCustomEvent', (data) => {
this.setState({
data,
})
})
}
componentWillUnmount() {
EventRegister.removeEventListener(this.listener)
}
render() {
return <Text>{this.state.data}</Text>
}
}
/*
* SENDER COMPONENT
*/
const Sender = (props) => (
<TouchableHighlight
onPress={() => {
EventRegister.emit('myCustomEvent', 'it works!!!')
})
><Text>Send Event</Text></TouchableHighlight>
)
// import
import { EventRegister } from 'react-events-listeners'
static method | return value | description |
---|---|---|
addEventListener | string | boolean | return value is the id of the event listener or false on error |
removeEventListener | boolean | true on success otherwise false |
removeAllListeners | boolean | true on success otherwise false |
emitEvent | void | no return value |
on | string | boolean | shorthand for addEventListener |
rm | boolean | shorthand for removeEventListener |
rmAll | boolean | shorthand for removeAllListeners |
emit | void | shorthand for emitEvent |
FAQs
(This package isn't only restricted to react-js projects. The source is written in plain js with no dependencies to react-js.)
The npm package react-events-listeners receives a total of 3 weekly downloads. As such, react-events-listeners popularity was classified as not popular.
We found that react-events-listeners demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.