react

GitHub

提供 React 组件编写规范,涵盖样式策略、组件库优先级(优先 base-ui)及常用 UI 组件导入方式,指导 TSX 开发。

.agents/skills/react/SKILL.md lobehub/lobehub

Trigger Scenarios

编辑 TSX 文件 选择 UI 组件库 处理组件样式

Install

npx skills add lobehub/lobehub --skill react -g -y
More Options

Non-standard path

npx skills add https://github.com/lobehub/lobehub/tree/canary/.agents/skills/react -g -y

Use without installing

npx skills use lobehub/lobehub@react

指定 Agent (Claude Code)

npx skills add lobehub/lobehub --skill react -a claude-code -g -y

安装 repo 全部 skill

npx skills add lobehub/lobehub --all -g -y

预览 repo 内 skill

npx skills add lobehub/lobehub --list

SKILL.md

Frontmatter
{
    "name": "react",
    "description": "LobeHub React component conventions. Use when editing TSX UI, choosing base-ui vs @lobehub\/ui vs antd, styling with antd-style, component boundaries, local state, layouts, render performance, or memoization.",
    "user-invocable": false
}

React Component Writing Guide

Styling

Scenario Approach
Most cases createStaticStyles + cssVar.* (zero-runtime, module-level)
Simple one-off Inline style attribute
Truly dynamic (JS color fns like readableColor/chroma) createStyles + tokenlast resort

Component Priority

  1. src/components — project-specific reusable components
  2. @lobehub/ui/base-ui — headless primitives. If the component lives here, use it. Do NOT import the same-named root export.
  3. @lobehub/ui — higher-level / antd-wrapping components (only when no base-ui equivalent)
  4. antd — only when neither base-ui nor @lobehub/ui root provides it
  5. Custom implementation — true last resort

If unsure about available components, search existing code or check node_modules/@lobehub/ui/es/index.mjs and node_modules/@lobehub/ui/es/base-ui/.

@lobehub/ui/base-ui — always prefer for these

Component Import
Alert (+ AlertProps) import { Alert, type AlertProps } from '@lobehub/ui/base-ui';
Select (+ SelectProps, SelectOption) import { Select } from '@lobehub/ui/base-ui';
Modal (imperative API) import { createModal, confirmModal, useModalContext, type ModalInstance } from '@lobehub/ui/base-ui';
DropdownMenu import { DropdownMenu } from '@lobehub/ui/base-ui';
ContextMenu import { ContextMenu } from '@lobehub/ui/base-ui';
Popover import { Popover } from '@lobehub/ui/base-ui';
ScrollArea import { ScrollArea } from '@lobehub/ui/base-ui';
Switch import { Switch } from '@lobehub/ui/base-ui';
Toast import { Toast } from '@lobehub/ui/base-ui';
FloatingSheet import { FloatingSheet } from '@lobehub/ui/base-ui';
Drawer import { Drawer } from '@lobehub/ui/base-ui';

For Modal specifically, see the dedicated modal skill — use the imperative createModal({ content: … }) pattern over the legacy <Modal open … /> declarative pattern. base-ui has its own ModalHost already mounted in SPAGlobalProvider.

Common slip: import { Select } from '@lobehub/ui' looks fine but it's the antd-backed Select. Use base-ui Select. Same for Modal, DropdownMenu, etc.

@lobehub/ui root — use when base-ui has no equivalent

Category Components
General ActionIcon, ActionIconGroup, Block, Button, Icon
Data Display Avatar, Collapse, Empty, Highlighter, Markdown, Tag, Tooltip
Data Entry CodeEditor, CopyButton, EditableText, Form, Input, InputPassword, SearchBar, TextArea
Layout Center, DraggablePanel, Flexbox, Grid, Header, MaskShadow
Navigation Burger, Menu, SideNav, Tabs

State

Keep transient state in its smallest useful owner. Extract a custom hook when state transitions and handlers obscure rendering or form a reusable unit; do not extract solely because a component has a particular number of hooks.

Split a component only to establish a real state, reuse, render-update, or mountable-capability boundary. Do not split solely to make files smaller. Decomposing a heavy domain feature into host-assembled atoms is owned by compose-atoms.

Render Performance and Memoization

Treat memo, useMemo, and useCallback as opt-in optimizations, not default component wrappers. Before adding one, identify the actual rerender boundary and prefer structural fixes:

  1. Split at the update boundary.
  2. Move transient state to its smallest owner.
  3. Use narrow Zustand selectors and avoid broad subscriptions.

Do not memoize prop-free or trivially rendered components, or a component that normally receives new objects, arrays, functions, or JSX children. Do not use memoization to compensate for state held too high in the tree.

Use memoization only when the subtree is demonstrably expensive or frequently repeated, its relevant inputs are stable during normal parent renders, and profiling or a concrete render-path analysis identifies the avoided work. State that reason in the implementation summary or PR.

Layout

Use Flexbox and Center from @lobehub/ui. See references/layout-kit.md for full props and examples.

  • Use gap instead of margin for spacing between flex children
  • Use flex={1} to fill available space
  • Nest Flexbox for complex layouts; set overflow: 'auto' for scrollable regions

Related Skills

  • ux: loading visuals and user-facing interaction design. Do not use antd Spin / <Spin />.
  • modal: imperative base-ui modal patterns.
  • spa-routes: SPA navigation, route ownership, router configuration, and .desktop variants.
  • compose-atoms: split a heavy domain feature into mountable capability atoms; each host imports only what it mounts.
  • zustand: store structure and selector conventions.

Version History

  • 29fe043 Current 2026-08-20 18:34

Same Skill Collection

.agents/skills/add-provider-doc/SKILL.md
.agents/skills/add-setting-env/SKILL.md
.agents/skills/agent-runtime-hooks/SKILL.md
.agents/skills/agent-signal/SKILL.md
.agents/skills/agent-testing-bot/SKILL.md
.agents/skills/agent-tracing/SKILL.md
.agents/skills/agent-work/SKILL.md
.agents/skills/builtin-tool/SKILL.md
.agents/skills/chat-sdk/SKILL.md
.agents/skills/cleanup-git-worktrees/SKILL.md
.agents/skills/cli/SKILL.md
.agents/skills/data-fetching-architecture/SKILL.md
.agents/skills/db-migrations/SKILL.md
.agents/skills/debug-package/SKILL.md
.agents/skills/deep-review/SKILL.md
.agents/skills/design-prototype/SKILL.md
.agents/skills/desktop/SKILL.md
.agents/skills/docs-changelog/SKILL.md
.agents/skills/drizzle/SKILL.md
.agents/skills/heterogeneous-agent/SKILL.md
.agents/skills/hotkey/SKILL.md
.agents/skills/i18n/SKILL.md
.agents/skills/linear/SKILL.md
.agents/skills/llm-generation/SKILL.md
.agents/skills/modal/SKILL.md
.agents/skills/model-bank-metadata/SKILL.md
.agents/skills/product-design/SKILL.md
.agents/skills/project-overview/SKILL.md
.agents/skills/response-compliance/SKILL.md
.agents/skills/skills-audit/SKILL.md
.agents/skills/spa-routes/SKILL.md
.agents/skills/split-micro-app/SKILL.md
.agents/skills/store-data-structures/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/trpc-router/SKILL.md
.agents/skills/typescript/SKILL.md
.agents/skills/upstash-workflow/SKILL.md
.agents/skills/ux-audit/SKILL.md
.agents/skills/ux/SKILL.md
.agents/skills/version-release/SKILL.md
.agents/skills/zustand/SKILL.md
.agents/skills/agent-testing/SKILL.md
.agents/skills/compose-atoms/SKILL.md
.agents/skills/debug-frontend-with-browser/SKILL.md
.agents/skills/pr/SKILL.md
packages/builtin-skills/src/acceptance/SKILL.md

Metadata

Files
0
Version
a06b4e2
Hash
cdc3371b
Indexed
2026-08-20 18:34

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-30 04:20
浙ICP备14020137号-1 $Carte des visiteurs$