smithery.ai

using-keys

ReactUMG key 使用规范。在渲染列表、map 循环、拖拽预览、动态组件等场景时激活。key 标识组件身份而非位置,禁止使用坐标/索引等频繁变化的值作为 key,避?

First seen Apr 23, 2026

Installation

$ npx skills add https://smithery.ai

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery.ai · top by installs.

npx skills add https://smithery.ai

Browse all from smithery.ai

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 1,851 B
  • docs SUMMARY.md 257 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 1 installs

SKILL.md

ReactUMG key 使用规范

核心原则

key 标识组件身份,不是状态!

❌ 绝对禁止:坐标作为 key

// ❌❌❌ 严重错误!每帧都重建组件
<DragPreview
    key={`${mouseX}-${mouseY}`}  // 鼠标移动就变!
    Slot={{Left: mouseX, Top: mouseY}}
/>
// 后果:性能崩溃、动画失效、大量 GC

✅ 正确做法:身份标识作为 key

// ✅ 正确:key 标识"这是哪个物品"
<DragPreview
    key={item.id}  // 只有换物品才变
    item={item}
    Slot={{Left: mouseX, Top: mouseY}}  // 位置通过 Slot 更新
/>

key 使用决策表

场景 key 值 正确性
列表渲染 item.id
拖拽预览 item.id
切换用户 userId
位置更新 ${x}-${y}
动画帧 frameIndex

React 的工作原理

// key 相同 → 复用组件,只更新 props
<Component key="fixed" Slot={{Left: 100}} />
<Component key="fixed" Slot={{Left: 150}} />
// React:调用 update(oldProps, newProps)

// key 不同 → 销毁旧组件,创建新组件
<Component key="a" />
<Component key="b" />
// React:RemoveChild(旧) + CreateWidget(新)

UE 开发者注意

// React 的 render() ≠ UE 的 CreateWidget()
render() {
    return <DragPreview key={item.id} />;
}
// 这不会每次都创建新 Widget!
// React 会复用 key 相同的组件

记住:key 应该回答"这是谁",而不是"它在哪里"或"它长什么样"。