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

ecs-react

v1.1.6

Published

A lightweight ECS framework for React

Readme

ecs-react

Minified Size

A lightweight Entity Component System (ECS) implementation for React applications. This architecture allows React components to serve purely as renderers, while all state management and business logic is handled by the ECS pattern.

This provides a type-safe and scalable way to manage complex state and behavior, particularly useful for any React application that benefits from decoupled state and rendering logic.

Installation

npm install ecs-react
# or
yarn add ecs-react

Why ECS over Traditional State Management?

Unlike traditional state management solutions like Redux or MobX, which organize state around a global store or observable objects, ecs-react takes a fundamentally different approach:

  • Composition over Global State: Instead of a global state tree, state is organized around entities and their components, making it easier to add/remove features dynamically
  • Behavior Separation: Systems handle logic independently of data (components) and presentation (React components), creating cleaner separation than reducer/action patterns

Overview

ecs-react implements the Entity Component System (ECS) pattern, which consists of:

  • Entities: Base objects that serve as containers for components
  • Components: Pure data containers that define the properties of entities
  • Systems: Logic that operates on entities with specific components
  • Signals: Events that trigger system behaviors

Core Concepts

👉 Complete example can be found here: examples/ecs-react-example

1. Defining Types

First, define your Component and Signal schemas:

import { ComponentSchema, SignalSchema } from "ecs-react";

// Define all your Component types
type MyComponents = ComponentSchema<{
  counter: { count: number };
  label: string;
}>;

// Define all possible Signal types
type MySignals = SignalSchema<"click" | "hover">;

2. Creating an ECS Instance

Create a typed instance of the ECS:

import { ECS } from "ecs-react";

const ecs = new ECS<MyComponents, MySignals>();

3. Working with Entities

Entities are created and managed through the ECS instance:

// Create a new entity
const counterEntity = ecs.createEntity();

// Add components to the entity
counterEntity.addComponent("counter", { count: 0 });
counterEntity.addComponent("lastUpdatedAt", { count: Date.now() });

4. Creating Systems

Systems define behavior that operates on entities when specific signals are received:

ecs.createSystem({
  name: "counterSystem",
  signals: ["click"],
  fn: ({ entity }) => {
    entity.updateComponent("counter", prevValue => ({
      count: prevValue.count + 1,
    }));
  },
});

The above system will run when the click signal is received.

5. Using with React Components

React components can interact with entities using the provided hooks:

import { useComponent, WithEntityProps } from "ecs-react";

// Button that executes the click signal on the counter entity
const Button: React.FC<WithEntityProps<MyComponents>> = ({ entity }) => {
  const onClick = () => ecs.signal("click", entity);

  return <button onClick={onClick}>Click</button>;
};

// Display component that shows the counter entity
const Display: React.FC<WithEntityProps<MyComponents>> = ({ entity }) => {
  // internally subscribes to updates on the counter component of the entity
  const counter = useComponent(entity, "counter");

  return <span>{counter?.count}</span>;
};

Contributing

Post any issues and suggestions on the GitHub issues page. To contribute, fork the project and then create a pull request back to main.