
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
react-observer-hooks
Advanced tools
A small React typescript library for sending events between components using observer pattern.
A small React typescript library for sending events between components. This is an observer pattern, where one component (or any piece of code) fires an event, while any other component can listen to it and handle the it if needed.
This is not a reactive way of doing things and in most cases it should not be needed since all of the component to component communication can be done using variuos React built-in features (state, props, context, etc).
A common scenario to use observer pattern in React app is when components under a different tree nodes needs to communicate with each other, or if we have a very big component tree and passing the same prop though all of the children makes no sense.
Typescript only. Hooks are typesafe and they will infer the argument types for events.
import {EventObserver, reateUseObserver, createUseStateForObserverEvent} from 'react-observer-hooks';
export enum ObserverEvent {
REPLY_PRESS,
POST_CREATED,
}
export interface ObserverEventArg {
[ObserverEvent.ON_REPLY_PRESS]: {parentId: string};
[ObserverEvent.POST_CREATED]: {postId: string};
}
export const observer = new EventObserver<ObserverEventArg>();
export const useObserver = createUseObserver(observer);
export const useStateForObserverEvent = createUseStateForObserverEvent<ObserverEventArg>();
export const PostFooter = ({parentId}: {parentId: string}) => {
const handleReplyPress = React.useCallback(
() => observer.notify(ObserverEvent.POST_CREATED, {parentId}),
[parentId]
);
return (
<>
...
<Button onPress={handleReplyPress}>
...
</>
);
};
export const BottomInput = ({parentId}: {parentId: string}) => {
const [selectedParent, setSelectedParent] = useStateForObserverEvent(ObserverEvent.ON_REPLY_PRESS);
useObserver(ObserverEvent.ON_REPLY_PRESS, (eventArgs) => {
setSelectedParent(eventArgs);
});
return (
<>
... selectedParent ? <ActiveInput /> : <InactiveInput />
...
</>
);
};
FAQs
A small React typescript library for sending events between components using observer pattern.
We found that react-observer-hooks 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
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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.