Reactive Proxy State

2 min read Original article โ†—

Reactive Proxy StateStandalone Reactivity System

A lightweight reactivity library inspired by Vue 3's reactivity system, designed for use in any JavaScript environment

๐Ÿš€ Lightweight & Fast

Small bundle size with zero dependencies, optimized for performance in both browser and Node.js environments.

๐Ÿงฉ Framework Agnostic

Use with any JavaScript framework or none at all. Perfect for state management, data synchronization, or real-time applications.

๐Ÿ”„ Deep Reactivity

Automatically tracks nested objects, arrays, Maps and Sets with deep reactivity that just works.

๐Ÿ› ๏ธ Familiar API

Based on Vue 3's composition API, making it easy to learn if you're already familiar with Vue.

๐Ÿ“ TypeScript Ready

Built with TypeScript and ships with full type definitions for an excellent developer experience.

๐Ÿงช Well Tested

Comprehensive test suite ensures reactivity works correctly in all edge cases.

Quick Example โ€‹

js

import { reactive, ref, computed, watchEffect } from '@yiin/reactive-proxy-state';

// Create reactive state
const count = ref(0);
const user = reactive({
  name: 'Alice',
  settings: { theme: 'dark' }
});

// Create a computed property
const greeting = computed(() => 
  `Hello, ${user.name}! Count is ${count.value}`
);

// Track changes with watchEffect
watchEffect(() => {
  console.log(greeting.value);
  console.log(`Theme: ${user.settings.theme}`);
});
// Output: Hello, Alice! Count is 0
// Output: Theme: dark

// Update state - effects automatically re-run
count.value++;
// Output: Hello, Alice! Count is 1
// Output: Theme: dark

user.name = 'Bob';
// Output: Hello, Bob! Count is 1
// Output: Theme: dark

user.settings.theme = 'light';
// Output: Hello, Bob! Count is 1
// Output: Theme: light

Installation โ€‹

bash

# Using bun (recommended for best performance)
bun add @yiin/reactive-proxy-state

# Using npm
npm install @yiin/reactive-proxy-state

# Using yarn
yarn add @yiin/reactive-proxy-state