
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-observable-hooks
Advanced tools
react library that allows to create and subscribe to observables, ideally for sharing state across differents components
This library is experimental, avoid using it on production unless you take responsability to fix the bugs
useObservable HookThe useObservable hook allows you to subscribe to an observable and get its state and status in your React component.
import React from 'react';
import { useObservable } from 'react-observable-hooks';
const MyComponent = () => {
const { state, dispatch } = useObservable('myObservable', 'initialValue');
return (
<div>
<button onClick={() => dispatch('newValue')}>Update Observable</button>
<p>the new value is: {state}</p>
</div>
);
};
useSubscribeObservable HookThe useSubscribeObservable hook allows you to subscribe to an observable and execute a handler function when the observable updates.
import React from 'react';
import { useSubscribeObservable } from 'react-observable-hooks';
const MyComponent = () => {
useSubscribeObservable('myObservable', (value) => {
console.log('Observable updated with value:', value);
});
return <div>Check the console for updates</div>;
};
createEffectWithTriggerThe createEffectWithTrigger function allows you to create an effect that triggers when a specific observable updates.
Always use it outside the components
import React from 'react';
import { useObservable, createEffectWithTrigger } from 'react-observable-hooks';
createEffectWithTrigger('triggerObservable', 'targetObservable', async (val) => {
// Perform some async operation
const result = await fetchSomeData(val);
return result;
});
const TriggerComponent = () => {
const { state, dispatch } = useObservable('triggerObservable', 'initialValue');
return (
<div>
<button onClick={() => dispatch('newValue')}>Update Observable</button>
</div>
);
};
const TargetComponent = () => {
const { state } = useObservable('targetObservable', 'initialValue');
return (
<div>
data fetched by the effect {state}
</div>
);
};
createDispachableEffectThe createDispachableEffect function allows you to create an effect that can be dispatched manually.
Always use it outside the components
import React from 'react';
import { createDispachableEffect } from 'react-observable-hooks';
//always create effects outside components
const dispatchEffect = createDispachableEffect('targetObservable', async (val) => {
// Perform some async operation
const result = await fetchSomeData(val);
return result;
});
const Dispacher = () => {
return <button onClick={() => dispatchEffect('someValue')}>Run Effect</button>;
};
const Subscriber = () => {
const { state, isLoading, isError, isResolved } = useObservable('targetObservable', 'initialValue');
return (
<div>
{isLoading && <p>Loading...</p>}
{isError && <p>Error occurred</p>}
{isResolved && <p>Data fetched: {state}</p>}
</div>
);
};
This documentation provides an overview of how to use the provided observable functions and hooks in your React components.
FAQs
react library that allows to create and subscribe to observables, ideally for sharing state across differents components
We found that react-observable-hooks 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.