
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
react-entity-component-system
Advanced tools
Entity Component System for React to make games or other interactive components.
An ECS hook for React to make games or other interactive components.
yarn add react-entity-component-system
It's fun to build games with React, and people have become successful at it. The ECS pattern is well known and battle tested for game development. This library is a loose implementation for React. You can check out the Breakout storybook story to see a fairly complex example.
import React from 'react'
import { useEntityComponentSystem } from 'react-entity-component-system'
ECS in general has three basic concepts:
Entities represent things in a sceneComponents (not React components) are data structures, composed to create entities.Systems are functions that operate on entities during every updateIn this implementation, an entity is defined as a plain object with at least a Renderer property (a React component). Other properties are components that will be passed as props to the Renderer:
const counterEntity = {
Renderer: props => <h4>{props.count}</h4>,
count: 0,
}
A system is just a function that operates on entities in the scene each frame. Systems are allowed to mutate the entities' components (thanks to immer!):
function frameCounterSystem({ entities }) {
entities.forEach(entity => entity.count++)
}
The useEntityComponentSystem hook manages the CRUD (creating, rendering, updating and destroying the entities). Pass it some initial entities and systems, receive the renderable result and an updater function:
const initialEntities = [counterEntity]
const systems = [frameCounterSystem]
export default function BasicECS() {
const [entities, updater] = useEntityComponentSystem(initialEntities, systems)
return (
<div>
<button onClick={() => updater()}>Next Frame</button>
{entities}
</div>
)
}
When the updater is called, all the systems are called with the following object as the first argument:
const systemArgs = {
entities: Object.values(entitiesDraft),
entitiesMap: entitiesDraft,
createEntity,
destroyEntity,
...userArgs,
}
The updater takes and object or function (which should return an object) and passes it to the systems (...userArgs as shown above) so they can have access to many other things. For example, the provided useKeysDown hook:
const keysDown = useKeysDown()
updater({
keysDown,
})
Typically, the updater is called inside a loop via the provided useGameLoop hook. Be sure the function you pass is not redefined during every render. In most cases, you should wrap the updater call in React.useCallback:
function Game(scene) {
const [entities, updater] = useEntityComponentSystem(...scene)
const update = useCallback(elapsedTime => updater({ elapsedTime }), [updater])
useGameLoop(update)
return <>{entities}</>
}
See this example and more in the stories folder
While react-entity-component-system is in development, you can check out the storybook to get a better sense of how things work.
git clone https://github.com/mattblackdev/react-entity-component-system.git
cd react-entity-component-system
yarn
yarn start
I welcome any ideas and would really love some help with:
FAQs
Entity Component System for React to make games or other interactive components.
We found that react-entity-component-system demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.