
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
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.
npm install ecs-react
# or
yarn add ecs-react
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:
ecs-react implements the Entity Component System (ECS) pattern, which consists of:
👉 Complete example can be found here: examples/ecs-react-example
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">;
Create a typed instance of the ECS:
import { ECS } from "ecs-react";
const ecs = new ECS<MyComponents, MySignals>();
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() });
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.
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>;
};
Post any issues and suggestions on the GitHub issues page. To contribute, fork the project and then create a pull request back to main.
FAQs
A lightweight ECS framework for React
The npm package ecs-react receives a total of 4 weekly downloads. As such, ecs-react popularity was classified as not popular.
We found that ecs-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.