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

relat

v0.1.0

Published

State manager for react

Readme

React State Manager Documentation

Overview

relat is a lightweight state management solution for React applications that uses JavaScript Proxies for automatic reactivity. It provides a simple API for creating global state containers that trigger re-renders when their properties change.

Key advantages:

  • 🚀 Zero-boilerplate state management
  • ⚡ Automatic dependency tracking
  • 🔥 Direct mutation API (no reducers/dispatchers)
  • 📦 <1KB minified (no dependencies)
  • 💡 Perfect for small-to-medium apps

Ideal for:

  • Developers who want simple global state
  • Projects needing Reactivity API similar to Vue
  • Teams migrating from useState/useContext

Installation

npm install relat
# or
yarn add relat

Initialization

Initialize in your app entry point (e.g., index.js):

// index.js
import { initFull } from 'relat';
import React from 'react';

initFull({
  useState: React.useState,
  useRef: React.useRef,
  useEffect: React.useEffect
});

Basic Usage

  1. Define state container
// store.js
import { defineFull } from 'relat';

export const counterState = defineFull({
  count: 0,
  increment() {
    this.count++;
  }
});
  1. Use in components
// Counter.jsx
import { useFull } from 'relat';
import { counterState } from './store';

function Counter() {
  const state = useFull(counterState);

  return (
    <div>
      <p>Count: {state.count}</p>
      <button onClick={state.increment}>+1</button>
    </div>
  );
}

Advanced Example

// authStore.js
import { defineFull } from 'relat';

export const authState = defineFull(() => ({
  user: null,
  isLoggedIn: false,
  login(email, password) {
    // Mock API call
    setTimeout(() => {
      this.user = { email, name: "John Doe" };
      this.isLoggedIn = true;
    }, 300);
  },
  logout() {
    this.user = null;
    this.isLoggedIn = false;
  }
}));
// AuthComponent.jsx
import { useFull } from 'relat';
import { authState } from './authStore';

function AuthComponent() {
  const { user, isLoggedIn, login, logout } = useFull(authState);
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');

  if (isLoggedIn) {
    return (
      <div>
        <h1>Welcome, {user.name}!</h1>
        <button onClick={logout}>Logout</button>
      </div>
    );
  }

  return (
    <form onSubmit={() => login(email, password)}>
      <input 
        type="email" 
        value={email}
        onChange={e => setEmail(e.target.value)}
      />
      <input 
        type="password" 
        value={password}
        onChange={e => setPassword(e.target.value)}
      />
      <button type="submit">Login</button>
    </form>
  );
}

API Reference

initFull(options)

Initializes the state manager with React hooks
Parameters:

  • options: Configuration object
    • useState: React's useState hook
    • useRef: React's useRef hook
    • useEffect: React's useEffect hook

Example:

initFull({
  useState: React.useState,
  useRef: React.useRef,
  useEffect: React.useEffect
});

defineFull(defaults)

Creates a state container
Parameters:

  • defaults: Initial state (object or factory function)

Returns:
State key (used with useFull)

Example:

const store = defineFull({
  counter: 0,
  todos: []
});

// With factory function
const configStore = defineFull(() => ({
  theme: 'dark',
  language: 'en'
}));

useFull(dataKey)

Hook for accessing state
Parameters:

  • dataKey: Key from defineFull

Returns:
Proxy object with your state

Example:

const state = useFull(store);
state.counter = 5; // Triggers re-render

Special Properties
  • __versionSymbol: Read-only version counter
console.log(state[__versionSymbol]); // 0,1,2...

Performance Notes

  1. For large state objects, avoid frequent top-level mutations
  2. Use nested objects carefully (shallow changes only trigger updates)
  3. Batch related changes:
// Instead of:
state.a = 1;
state.b = 2;

// Do:
Object.assign(state, { a: 1, b: 2 });

Testing

Use included test utilities:

import { render, screen } from '@testing-library/react';
import { defineFull, useFull } from 'relat';

test('state updates', async () => {
  const store = defineFull({ count: 0 });
  
  function TestComponent() {
    const state = useFull(store);
    return <div onClick={() => state.count++}>{state.count}</div>;
  }
  
  render(<TestComponent />);
  
  await userEvent.click(screen.getByText('0'));
  expect(screen.getByText('1')).toBeInTheDocument();
});