
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-create-event
Advanced tools
A simple library for sending events between React components (aka client-side pub/sub).
Features:
useListen hook.npm install react-create-event
Create the event, and and export it (it's recommended to create them in one file):
// File: events.ts | events.js
import { createEvent } from "react-create-event";
export const hitEvent = createEvent();
Fires the event:
import { hitEvent } from "../events";
export function Hitter() {
return <button onClick={() => hitEvent.fire()}>Hit</button>;
}
Listen for the event:
import { hitEvent } from "../events";
export function HitCounter() {
const [count, setCount] = useState(0);
hitEvent.useListen(() => {
setCount((c) => c + 1);
}, []);
return <div>Count: {count}</div>;
}
import { createEvent } from "react-create-event";
export interface Coordinates {
x: number;
y: number;
}
// First type is the "details" sent with each event.
// Second type is the return type, returned by each listener.
export const torpedoEvent = createEvent<Coordinates, boolean | void>();
Fire the event:
import { torpedoEvent } from "../events";
export function TorpedoLauncher() {
const [hitCount, setHitCount] = useState(0);
const fireTorpedo = useCallback(() => {
const x = Math.floor(Math.random() * 10);
const y = Math.floor(Math.random() * 10);
const results = torpedoEvent.fire({ x, y });
const hits = results.filter((r) => r).length;
setHitCount((hC) => hC + hits);
}, []);
return <>
<button onClick={fireTorpedo}>FIRE TORPEDO!</button>
<div>Successful hits so far: {hitCount}</button>
</>;
}
Listen for the event:
import { torpedoEvent, type Coordinates } from "../events";
export function Ship({ x, y }: Coordinates) {
const [hitCount, setHitCount] = useState(0);
torpedoEvent.useListen(
(details: Coordinates) => {
if (details.x === x && details.y === y) {
setHitCount((hC) => hC + 1);
return true;
}
},
[x, y] // hook dependencies
);
return <div>Times this ship was hit: {hitCount}</div>;
}
Copyright Jon Abrams (2024)
FAQs
A simple library to send events between React components.
The npm package react-create-event receives a total of 313 weekly downloads. As such, react-create-event popularity was classified as not popular.
We found that react-create-event demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.