
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.
valtio-reactive
Advanced tools
Reactive primitives for valtio — adds, computed, effect, and batch to enable fine-grained reactivity outside of React.
valtio's reactive capabilities are primarily designed for React via useSnapshot and only has limited support for computed values. valtio-reactive was made to fill those gaps while keeping valtio lean and fast.
See the original discussion for more context.
npm install valtio valtio-reactive
This runs the first function (fn) immediately and re-runs it whenever any of the properties that are accessed in that function change. Only the properties are actually read during execution are tracked — changes to unread properties won't trigger re-runs. It returns a dispose function that will run the cleanup function when called.
import { proxy } from 'valtio/vanilla';
import { effect } from 'valtio-reactive';
const state = proxy({
count: 0,
unrelated: 'hello'
user: {
settings: {
theme: 'light' //
},
name: 'Bob'
},
})
const dispose = effect(
() => {
console.log('count is: ', state.count)
console.log('theme is: ', state.user.settings.theme)
},
() => {
// optional cleanup function
console.log('cleaning up')
}
)
// immediately logs:
// "count is: 0"
// "theme is: light'
state.count++
// logs:
// "count is: 1"
// "theme is: light"
state.unrelated = 'world' // nothing happens when this property is changed because it wasn't accessed
state.user.name = 'Robert' // nothing happens
state.user.settings.theme = 'dark'
// logs:
// "count is: 1"
// "theme is: dark"
dispose()
// logs "cleaning up"
batch(fn): TBatches multiple state changes so that effects only react once after all changes complete. Returns the value returned by fn.
import { proxy } from 'valtio/vanilla';
import { batch, effect } from 'valtio-reactive';
const state = proxy({ count: 0 });
effect(() => {
console.log('count:', state.count);
});
// Logs: "count: 0"
batch(() => {
state.count++;
state.count++;
state.count++;
});
// Logs: "count: 3" (only once, not three times)
computed(obj): TCreates a proxy object with computed/derived properties. Each property is defined as a getter function that automatically re-runs when its dependencies change.
import { proxy } from 'valtio/vanilla';
import { computed } from 'valtio-reactive';
const state = proxy({ count: 1 });
const derived = computed({
double: () => state.count * 2,
quadruple: () => state.count * 4,
});
console.log(derived.double); // 2
console.log(derived.quadruple); // 4
state.count = 5;
console.log(derived.double); // 10
console.log(derived.quadruple); // 20
The returned object is itself a valtio proxy, so you can use it with effect, useSnapshot, or any other valtio utility.
While these primitives are framework-agnostic, they integrate seamlessly with valtio's React bindings:
import { proxy, useSnapshot } from 'valtio';
import { effect, computed } from 'valtio-reactive';
const state = proxy({ count: 0 });
// Computed values work with useSnapshot
const derived = computed({
double: () => state.count * 2,
});
// Side effects outside of React
effect(() => {
console.log('Count changed:', state.count);
});
function Counter() {
const snap = useSnapshot(state);
const derivedSnap = useSnapshot(derived);
return (
<div>
<p>Count: {snap.count}</p>
<p>Double: {derivedSnap.double}</p>
<button onClick={() => state.count++}>+1</button>
</div>
);
}
All exports are fully typed. The computed function infers types from your getter functions:
const state = proxy({ count: 1, name: 'test' });
const derived = computed({
double: () => state.count * 2, // inferred as number
message: () => `Hello ${state.name}`, // inferred as string
});
derived.double; // number
derived.message; // string
MIT
FAQs
valtio-reactive makes Valtio a reactive library
We found that valtio-reactive demonstrated a healthy version release cadence and project activity because the last version was released less than 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
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.