JavaScript lets us freely mutate objects:
user.name = "John"; user.age = 25;
But this doesn't trigger any change detection — unless we use a large framework like React, Vue, MobX, or Immer.
Most existing solutions rely on:
❌ Immutable updates (React setState)
❌ Deep cloning (performance cost)
❌ Heavy reactivity systems (Vue, MobX)
❌ Framework-specific abstractions
❌ Large bundles just to track simple changes
Sometimes, we just want something:
✔ Tiny
✔ Framework-agnostic
✔ Native mutation
✔ Safe and reactive
That’s why I built VRef.
VRef is a tiny JavaScript utility that lets you:
✅ Mutate values directly (no immutability, no cloning)
🪝 Get notified when changes happen
⚡ Works with objects, arrays, Maps, Sets
🗑 Safe with Garbage Collection
🌍 Works in both browser & Node.js
npm install vref
import ref from "vref"; // Create a reactive object with a change tracker const { value: user } = ref( // User's initial value { name: "John", age: 25 }, // Change event handler (event) => { console.log("Changed:", event); } ); user.name = "Doe"; // triggers change event user.age = 26; // triggers change event
📌 Key point: You mutate normally, but VRef detects and reports changes.
Most libraries force you to use:
But sometimes, you just want to write this:
cart.items.push({ id: 1, qty: 2 });
And still know when and what changed — without deep cloning, proxies everywhere, or big abstractions.
Proxy.set, delete, get).const { value: todos } = ref([], (e) => console.log(e)); todos.push("Learn VRef"); // triggers todos[0] = "Practice VRef"; // triggers
const { value: settings } = ref(new Map(), (e) => console.log(e)); settings.set("theme", "dark"); // triggers
| Use case | Is VRef good? |
|---|---|
| Logging object mutations | ✅ Yes |
| Undo/redo or time-travel state | ✅ Yes |
| Form input tracking | ✅ Yes |
| Framework-level state management | ⚠️ Maybe |
| Full UI reactivity (React/Vue) | ⚠️ Maybe |
| Feature | VRef | MobX | Immer | Vue Reactivity |
|---|---|---|---|---|
| Tiny | ✔️ | ❌ | ❌ | ❌ |
| Direct mutation | ✔️ | ✔️ | ✔️ | ❌ |
| Change tracking | ✔️ | ✔️ | ⚠️ | ✔️ |
| Framework-free | ✔️ | ❌ | ✔️ | ❌ |
VRef is not meant to replace state management libraries or frameworks.
It’s a primitive, lightweight utility for simple, safe, reactive mutation and change tracking — nothing more, nothing less.
🎯 Perfect when you want:
“I just want to know when something changes — without rewriting my whole app.”
Play with vref:
👉 Open Live Playground
🟢 npm: https://www.npmjs.com/package/vref
🐙 GitHub: https://github.com/JohnSoatra/vref
💬 What do you think?
Would you find this useful in reactive state, logging, debugging, undo/redo, or form tracking?
I'd love feedback and suggestions!
📬 Contact me 👉 LinkedIn – John Soatra