@dcl/react-ecs

中文文档
7.33.0发布于 2026/11/06Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 1.3万

Decentraland ECS

原始使用文档
文档目录12 节
  1. Features
  2. Component Guidelines
  3. Installation
  4. Basic Usage
  5. Theme System
  6. Components
  7. Core Components
  8. Layout System
  9. Event Handling
  10. Technical Details
  11. Related Documentation
  12. License

@dcl/react-ecs

React bindings for Decentraland's Entity Component System (ECS), providing a declarative way to build UIs in Decentraland scenes using React's component model and JSX syntax.

Features

  • Flexbox-based Layout: Implements a subset of CSS Flexbox for powerful and intuitive UI layouts
  • React Components: Familiar React-like component API for building UIs
  • Type Safety: Full TypeScript support with proper type definitions
  • Event Handling: Support for mouse events and user interactions
  • Performance: Optimized reconciliation for minimal runtime overhead
  • Theme Support: Built-in light and dark theme system with context-based switching

Component Guidelines

All components in @dcl/react-ecs must:

  • Return JSX.Elements for consistency and composability
  • Support theme integration through context
  • Be reusable and composable with other components

Installation

npm install @dcl/react-ecs

Basic Usage

import { ReactEcs, UiEntity, Label, Button } from '@dcl/react-ecs'

export function MyUI() {
  return (
    <UiEntity
      uiTransform={{
        width: 300,
        height: 100,
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center'
      }}
    >
      <Label value="Hello Decentraland!" />
      <Button value="Click Me!" onMouseDown={() => console.log('clicked!')} />
    </UiEntity>
  )
}

Theme System

The package includes a theme system for consistent UI styling:

import { ReactEcs, ThemeProvider, Button } from '@dcl/react-ecs'

// Wrap your UI with ThemeProvider
export function MyUI() {
  return (
    <ThemeProvider>
      <Button value="Theme-Aware Button" />
    </ThemeProvider>
  )
}

// Use themes in custom components
function CustomComponent() {
  const { theme, toggleTheme } = React.useContext(ThemeContext)

  return (
    <UiEntity
      uiBackground={{
        color: theme === 'light' ? '#FFFFFF' : '#000000'
      }}
      onMouseDown={toggleTheme}
    />
  )
}

Components

Core Components

  • UiEntity: Base component for UI elements
  • Label: Text display component
  • Button: Interactive button component
  • Input: Text input field
  • Dropdown: Selection dropdown menu

Layout System

The layout system is based on Flexbox and supports the following properties:

  • display: 'flex'
  • flexDirection: 'row' | 'column'
  • justifyContent: 'flex-start' | 'center' | 'flex-end' | 'space-between' | 'space-around'
  • alignItems: 'flex-start' | 'center' | 'flex-end' | 'stretch'
  • width, height
  • margin, padding
  • positionType: 'absolute' | 'relative'

Event Handling

Components support the following mouse events:

<Button onMouseDown={() => {}} onMouseUp={() => {}} onMouseEnter={() => {}} onMouseLeave={() => {}} />

Technical Details

The package implements a custom React reconciler that bridges React's component model with Decentraland's ECS. It:

  1. Translates JSX into ECS entities and components
  2. Manages component lifecycle and updates
  3. Handles event delegation and bubbling
  4. Provides a performant update mechanism

For more details about the UI system architecture and design decisions:

License

Apache 2.0

版本与发布记录

@dcl/react-ecs 共发布 1,298 个版本,首次发布于 2022/09/12;过去 12 个月发布了 318 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
7.33.0latest2026/11/066 天前
7.32.1-42077145652.commit-f6053ef2026/11/066 天前
7.32.1-42074770886.commit-f6053ef2026/11/066 天前
7.32.1-41691874543.commit-3063788auth-server2026/11/047 天前
7.31.1-41669733463.commit-b1b1d792026/11/048 天前
7.32.02026/11/048 天前

其他发布通道:ci → 7.8.16,protocol-squad → 7.25.1-30828532396.commit-0c215c3,experimental → 7.27.1-34382248832.commit-ca3b679,experimental-bevy → 7.31.1-40604676255.commit-cb3ed84,experimental-bevy-auth-server → 7.31.1-40606969412.commit-24c05c3,auth-server → 7.32.1-41691874543.commit-3063788。

关于 @dcl/react-ecs 的常见问题

@dcl/react-ecs 是什么?

Decentraland ECS

如何安装 @dcl/react-ecs?

在项目目录运行 npm install @dcl/react-ecs,或使用 pnpm add / yarn add / bun add。

@dcl/react-ecs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dcl/react-ecs 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dcl/react-ecs 可以商用吗?

@dcl/react-ecs 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dcl/react-ecs 的下载量有多少?

根据 npm 官方下载统计,@dcl/react-ecs 在 2026/10/12 – 2026/11/10 这 30 天内被下载 12,578 次,日均约 419 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dcl/react-ecs 还在维护吗?

最新版本 7.33.0 发布于 2026/11/06(6 天前);至今共发布 1298 个版本,其中过去 12 个月发布了 318 个;首次发布于 2022/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。