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

elegant-store

v3.2.7

Published

An elegant, zero-dependency, highly performant state management solution for React.

Readme

React State Management with elegant-store

An elegant, zero-dependency, highly performant state management solution for React.

elegant-store combines the simplicity of React hooks with an efficient publish/subscribe pattern. In version 2, we've upgraded the core engine to leverage React 18's useSyncExternalStore for concurrent rendering safety and introduced powerful new features like selectors, async actions, and external state access.

Installation

npm install elegant-store

Usage

import { createStore } from "elegant-store";

// Define your store with an initial value and optional actions
const counterStore = createStore(0, {
  increment: (state) => state + 1,
  decrement: (state) => state - 1,
  reset: () => 0,
});

function Counter() {
  const { state: count, setState: setCount, increment, decrement, reset } = counterStore.useStore();

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>Increment</button>
      <button onClick={decrement}>Decrement</button>
      <button onClick={reset}>Reset</button>

      {/* You can still use setCount directly if needed: */}
      <button onClick={() => setCount(10)}>Set to 10</button>
    </div>
  );
}

Features & Upgrades

Performance & Safety (React 18)

The library now uses useSyncExternalStore under the hood. This eliminates tearing during concurrent rendering and ensures that your components always see the most up-to-date state, even if they mount after a state change.

Selectors (Preventing Re-renders)

If your state is a large object, you can pass a selector function to the hook to only re-render when a specific part of the state changes.

const userStore = createStore({ name: "Alice", age: 30 });

function UserProfile() {
  // Component will only re-render if `name` changes. Changes to `age` are ignored.
  const { state: name } = userStore.useStore((state) => state.name);

  return <div>Name: {name}</div>;
}

Async Actions Support

Actions can now be asynchronous! Just return a Promise, and the state will be updated when the Promise resolves.

const authStore = createStore({ user: null }, {
  login: async (state, credentials) => {
    const user = await api.login(credentials);
    return { ...state, user };
  }
});

Accessing State Outside of React Components

You can now read, update, or subscribe to the state outside of React components—perfect for utility files, API callers, or Router guards.

const tokenStore = createStore({ token: null });

// Outside React
const currentToken = tokenStore.get().token;
tokenStore.setState({ token: "new_token" });
tokenStore.actions.myAction();
tokenStore.subscribe((newState) => console.log(newState));

API

createStore<T, S>(initialValue: T, actions?: S, listeners?: ((t: T) => void)[])

Creates a new store.

Parameters:

  • initialValue: T: The initial value of the store.
  • actions?: S: An optional object containing action creators. Each action creator takes the current state and returns a new state (or a Promise resolving to a new state).
  • listeners?: ((t: T) => void)[]: An optional array of callbacks called with the new state value whenever the state changes.

Returns: An object containing:

  • useStore(selector?): A hook returning { state: selectedValue, setState: setValue, ...boundActions }
  • get() / getState(): Returns current state.
  • setState(newState): Updates current state.
  • actions: Your bound actions.
  • subscribe(listener): Subscribe to state changes.

AI Agent Instructions

Are you using an AI assistant like Cursor, Claude, or GitHub Copilot? We've created a dedicated markdown file specifically optimized for AI consumption. Feed docs/llms.md to your agent to ensure it generates perfect elegant-store code with selectors, async actions, and outside-React state access.

Bundling

This package uses bunchee to automatically build standard ESM/CJS bundles. The main entry point handles strict zero-config TypeScript compilation.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

MIT