The Simplest and the lightest event management tool.
Report Bug
·
Request Feature
Hey and welcome. You have started the development with the Simplest and lightest event management tool
You don't need to read huge docs or watch videos for hours to start using this.
Just read a few sentences below
Create a new file and name it Emitter
Import Emiiter in new Emiiter File and declare it.
Export the Emitter
Emiiter.js
import Emitter from 'boom-js-emitter'
const Emitter = new Emitter()
export default Emitter
Import the Emitter you have declared wherever you want.
Create a useEffect and declare an event in it using the subscribe function
import React, { useEffect } from 'react'
import Emitter from './../Emitter' // The file you have created
const SomeComponent = () => {
useEffect(() => {
Emitter.subscribe("MY_EVENT_NAME", (payload) => {
console.log("Doing something with my data", payload);
})
}, [])
return (
<>
The component which I'm proud for
</>
)
}
export default SomeComponent
subscribe
creates an event with this name if the event doesn't exist and starts listening to him
When the component is dead just call the unsubscribe function
import React, { useEffect } from 'react'
import Emitter from './../Emitter' // The file you have created
const SomeComponent = () => {
useEffect(() => {
Emitter.subscribe("MY_EVENT_NAME", (payload) => {
console.log("Doing something with my data", payload);
})
return () => Emitter.unsubscribe("MY_EVENT_NAME")
}, [])
return (
<>
The component which I'm proud for
</>
)
}
export default SomeComponent
I have nothing to say just look at the codes
import React from 'react'
import Emitter from './../Emitter' // The file you have craeted
const SomeOtherComponent = () => {
const handleTriggerEvent = () => Emitter.emit("MY_EVENT_NAME", "data 1", "data 2", "and so on ...")
return (
<div onClick={handleTriggerEvent}>
Trigger the event
</div>
)
}
export default SomeOtherComponent
This is not a code this is just a
Tigran Nazaryan | Ararat Matinyan | Sahak Sahakyan |