npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-binding-state

v1.2.3

Published

A lightweight and easy-to-use React library for two-way data binding, simplifying state management and enhancing developer productivity.

Readme

react-binding-state

NPM Version NPM Downloads License

A lightweight, easy-to-use state management library for React that enables deep two-way data binding. It uses ES6 Proxies to automatically detect and update state changes, even in nested objects, without the need for manual setters or reducers.

Live Demo

Check out the live demo here: https://nmhung1210.github.io/react-binding-state

Key Features

  • Deep Two-Way Data Binding: Automatically syncs your UI with your state, even for deeply nested objects.
  • Zero Boilerplate: No actions, reducers, or dispatchers needed. Just mutate the state directly.
  • Lightweight: A small footprint, adding minimal overhead to your project.
  • Intuitive API: A simple and straightforward API that is easy to learn and use.
  • TypeScript Support: Written in TypeScript for a better developer experience with type safety and autocompletion.

Installation

npm install react-binding-state

Usage

1. Define Your State Type (Optional but Recommended)

For the best experience, define a type for your global state.

// src/types.ts
export type AppState = {
  user: {
    name: string;
    profile: {
      email: string;
    };
  };
  counter: number;
};

2. Wrap Your App with BindingStateProvider

Provide the global state to your application by wrapping your root component with BindingStateProvider.

// src/main.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { BindingStateProvider } from 'react-binding-state';
import './App.css'; // Import global styles
import { AppState } from './types';

const initialState: AppState = {
  user: {
    name: 'John Doe',
    profile: {
      email: '[email protected]',
    },
  },
  counter: 0,
};

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <BindingStateProvider initialState={initialState}>
      <App />
    </BindingStateProvider>
  </React.StrictMode>
);

3. Use the useBindingState Hook

Access and mutate the state from any component using the useBindingState hook. Changes are automatically reflected in your UI.

// src/App.tsx
import React from 'react';
import { useBindingState } from 'react-binding-state';
import { AppState } from './types';

function UserProfile() {
  const state = useBindingState<AppState>();

  return (
    <div className="card">
      <h2>User Profile</h2>
      <p>Name: <strong>{state.user.name}</strong></p>
      <p>Email: <strong>{state.user.profile.email}</strong></p>
      <input
        type="text"
        value={state.user.name}
        onChange={(e) => {
          state.user.name = e.target.value;
        }}
      />
    </div>
  );
}

function Counter() {
    const state = useBindingState<AppState>();

    return (
        <div className="card">
            <h2>Counter</h2>
            <p>Count: <strong>{state.counter}</strong></p>
            <div className="button-group">
                <button onClick={() => state.counter++}>Increment</button>
                <button onClick={() => state.counter--}>Decrement</button>
            </div>
        </div>
    )
}

function App() {
  return (
    <div className="app-container">
      <h1>React Binding State Demo</h1>
      <UserProfile />
      <Counter />
    </div>
  );
}

export default App;

How It Works

react-binding-state leverages a React Context to provide a global state object wrapped in an ES6 Proxy. When you modify a property on the state proxy (e.g., state.user.name = 'Jane Doe'), the proxy’s set trap is triggered. This trap efficiently updates the underlying state and triggers a re-render of only the components that use the modified state, ensuring your UI is always in sync with your data with minimal performance overhead.

TypeScript Support

This library is written in TypeScript to provide a first-class development experience.

  • Type-Safe State: By providing a type to the useBindingState hook (e.g., useBindingState<AppState>()), you get full type safety and autocompletion for your state object.
  • Reduced Bugs: Catch typos and other errors at compile time, not at runtime.
  • Improved Readability: Type definitions make your code easier to understand and maintain.

Performance Benchmarks

Here's a summary of the benchmark results comparing BindingState with the native useState hook:

Benchmark Environment

  • CPU: AMD EPYC 7B12 (2 Cores)
  • Memory: 8 GB

Results

| Benchmark | BindingState (ops/sec) | useState (ops/sec) | Winner | Performance Gain | | ---------------------------------- | ---------------------- | -------------------- | -------------- | ---------------- | | Initial Render with Heavy State | 458.59 | 588.06 | useState | 1.28x | | Heavy Simple State Update | 11,875.21 | 2,007.02 | BindingState | 5.92x | | Heavy Deeply Nested State Update | 19,872.92 | 3,096.64 | BindingState | 6.42x | | Heavy Array Item Update | 21,289.86 | 3,869.84 | BindingState | 5.50x |

Conclusion

The benchmark results highlight a clear trade-off:

  • useState excels at initial rendering, offering a 1.28x performance advantage due to its native and highly optimized nature.
  • BindingState is significantly faster for all types of state updates, with performance gains ranging from 5.50x to 6.42x. The most substantial improvements are seen in scenarios with deeply nested objects, where BindingState's direct mutation approach avoids the performance overhead of manual immutable updates.

In summary, for applications with complex state and frequent updates, BindingState provides a compelling combination of performance and developer experience. If initial render time is the highest priority, useState may be a better choice. However, for applications where the user experience is defined by frequent state changes, BindingState offers a significant performance advantage.

Test Coverage

------------------|---------|----------|---------|---------|-------------------
File              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------|---------|----------|---------|---------|-------------------
All files         |     100 |      100 |     100 |     100 |                   
 BindingState.tsx |     100 |      100 |     100 |     100 |                   
------------------|---------|----------|---------|---------|-------------------

License

This project is licensed under the MIT License. See the LICENSE file for details.