Guidelines for writing consistent React components, choosing the right UI primitives, and applying modular styling.
Install
mkdir -p .claude/skills/react && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/627" && unzip -o skill.zip -d .claude/skills/react && rm skill.zipInstalls to .claude/skills/react
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
LobeHub React component conventions. Use when editing TSX UI, choosing base-ui vs @lobehub/ui vs antd, styling with antd-style, routing, desktop variants, layouts, or component state.Key capabilities
- →Develop React components using TSX
- →Select appropriate UI primitives from base-ui or antd
- →Implement styling with createStaticStyles
- →Manage routing with react-router-dom
- →Sync desktop variants for Electron
How it works
The skill enforces a component hierarchy that prioritizes headless base-ui primitives over higher-level wrappers, ensuring consistent styling and state management.
Inputs & outputs
When to use react
- →Create a new UI component
- →Implement component styling
- →Select appropriate UI primitives
- →Refactor component structure
About this skill
React Component Writing Guide
Styling
| Scenario | Approach |
|---|---|
| Files already on StyleX, and new SPA styles | stylex.create + @lobehub/ui/stylex/cssVar.stylex / @lobehub/ui/stylex/media.stylex. The SPA compiler is plugins/vite/stylex.ts (@stylexjs/unplugin, prefix lh). Do not copy those token modules into the app. |
| Existing styles not yet migrated | createStaticStyles + cssVar.* (zero-runtime, module-level) |
| Simple one-off | Inline style attribute |
Truly dynamic (JS color fns like readableColor/chroma) | createStyles + token — last resort |
StyleX
- New code may not import
createStaticStyles/createStyles/css/keyframes/createGlobalStyle/injectGlobalfrom@lobehub/ui(stylex-migration/no-emotion-styles). Files still on them are listed inscripts/stylexMigration/legacyFiles.json; after migrating one, runbun run stylex:migration --prune-legacy. Never add entries. - New code may not import a plain
.cssfile either (stylex-migration/no-plain-css; CSS modules and package stylesheets are fine). Files that already do are listed inscripts/stylexMigration/plainCssImporters.json, which only shrinks. - Migrate a whole file at once. StyleX longhand rules carry raised specificity (
.x:not(#\#)) and beat emotion classes on the same element, but StyleX shorthand rules do not, so a half-migrated element resolves by property. - Element that also forwards a caller's
className/style:{...sx(styles.root, active && styles.active, className, style)}from@/styles/sx. Arguments are variadic likestylex.props: strings become class names and plain objects merge into the inline style, so pass only what you have (sx(styles.bg, { backgroundImage })), never an array or anundefinedplaceholder. Spreadingstylex.propsnext toclassNamefails@stylexjs/no-conflicting-props. - Component that lets callers restyle it: take
xstyle?: StyleXStylesand pass it last in thesx/stylex.propsarray. A plainclassNamefrom outside cannot override StyleX rules. Passing a class to@lobehub/uicomponents (className,classNames) works, because lobe-ui CSS sits in@layer lobe-ui. - Values follow
@stylexjs/valid-styles: no multi-value shorthands (margin: '0 8px'→marginBlock/marginInline), and stringflex(flex: '1'). background,animation,borderandborder{Top,Right,Bottom,Left}shorthands compile to no class at all, whatever the value (border: 'none'included), without an error. Write longhands:backgroundColor(plusbackgroundImage: 'none'when replacing abackgroundshorthand),animationName/animationDuration/ …,borderWidth/borderStyle/borderColor.- Traps that compile cleanly but render differently from the emotion original (each one shipped in the migration stack):
all: 'unset'compiles to nothing. Write the resets out (appearance,margin,padding,border*,font: 'inherit',textAlign, …).- Keep reset semantics:
outline: none→outline: 'none'(notoutlineStyle);border: 0→borderWidth: 0+borderStyle: 'none'+borderColor: 'currentcolor';font: inherit→font: 'inherit', not a few font longhands; reduced-motionanimation: none→ resetanimationName,animationDuration,animationTimingFunction,animationIterationCount(andanimationFillModeif set). Insidestylex.keyframes,backgroundcompiles to an empty frame: usebackgroundColor. - Longhands always beat shorthands, whatever the order:
paddingBlockStartbeatspaddingBlock,flexShrinkbeatsflex. Two overlapping shorthands (borderWidth: 0withborderInlineWidth: '1px') do not layer either: write disjoint ones (borderBlockWidth+borderInlineWidth). Merged styles must write a property at the same level. - Order: lobe-ui
cx(a, b)callsemotion.cx, which merges classes from the same emotion cache in argument order (last wins), the same asstylex.props(a, b). Only what it cannot merge (plain strings, StyleX classes, another cache) falls back to stylesheet order. Keep the original argument order unless the base actually renders otherwise. - A per-property map replaces the whole map: a state style (
active,selected) that setsbackgroundColorwipes an earlier':hover'on it, and{ default: null, ':hover': x }wipes an earlier style's default. Carry both:{ default: <state>, ':hover': <hover> }. - Dynamic StyleX functions carry their values in an inline
style: spreadstylex.props(fn(x))or usesx, never.classNamealone. StyleX objects passed intocx()vanish. - Keep physical edges and corners when the original used them (
border-radius: 0 r r 0→borderTopRightRadius…); logical properties flip in RTL. - Strict media ranges:
620px < widthcompiles towidth >= 620.01px, which Chrome matches at a 620px viewport. For disjoint ranges write620.02px <= width. - Do not add declarations the original did not have (a
transitionon an element nothing animates). stylex.when.ancestor(...)without a marker listens to every ancestor carryingstylex.defaultMarker(), including unrelated wrappers (a scroll container, a layout cell). For a hover / focus reveal give the owner a privatestylex.defineMarker()from amarkers.stylex.tsbeside it.stylex.when.siblingBefore(...)compiles to the general sibling combinator~, not+, and only sees siblings that carry the marker. It reproduces& + &only when the matching siblings are always contiguous and marked; otherwise pass an explicit prop (divided,index > 0).- Keep
!importantwhen the competitor is an inline style: lobe-ui writes some properties inline (ActionIcon / Avatar with a numericsize→borderRadius,width; Image →maxWidth). Without it the inline value wins; pass the value through the component'sstyleinstead. - A caller's StyleX className passed through
classNameinto a component that applies its own StyleX on the same property gives one element two atomic classes for it, and the build's sort order (not argument order) picks the winner. Restyle our own components through anxstyleprop merged last.
- Check a migration in dev with the DevDock snapshot helper: on the migrated page run
__lobeStyleSnapshot.capture('<name>', '<root selector>'), back up the migrated files with their relative paths into a fresh directory (BACKUP=$(mktemp -d) && rsync -R <paths> "$BACKUP/"), swap in the originals (git checkout HEAD -- <paths>), reload, run__lobeStyleSnapshot.compare('<name>'), then restore the migrated files (cp -R "$BACKUP"/. ./). Do not usegit stash: every checkout shares one stash stack, and apushwith nothing to save creates no entry, so the nextpopapplies an older one. Each pair reads[captured, current], here[migrated, original]. It lists elements and::before/::afterwhose tracked computed styles, box (relative to the root) or text differ; an empty list means those match, not that hover, focus or closed dialogs were checked, so open each state you migrated and compare it too. Keep the window size, scroll everything under the root back to the start, and move the pointer off the compared area. bun run stylex:migration --list <A|B|C|D>lists files by how hard they are to move: A flat, B self pseudo-classes, C descendant / ancestor coupling (usestylex.defaultMarker()+stylex.when.ancestor()orxstyle), D tag / third-party DOM selectors (see the next rule).- Never move a selector into a plain
.cssfile to escape StyleX. Reach the element through an API instead, in this order:- The component's slot props. lobe-ui components take
classNames/stylesper part, e.g.Tabs→classNames={{ list: stylex.props(styles.tabList).className, tab: stylex.props(styles.tab).className }}. - A pseudo-class on the slot's element: StyleX compiles keys like
':has([data-replace-all])'and':nth-child(2)', so.tabs [role=tab]:has([data-replace-all])becomesclassNames.tabwithmarginInlineStart: { default: null, ':has([data-replace-all])': 'auto' }. - Our own component: add an
xstyle?: StyleXStylesprop (or<part>Xstylefor an inner part) and apply it there. - Only DOM no prop can reach (editor content such as
.ProseMirror p, rendered markdown, third-party widgets, lobe-ui parts without a slot) keeps its original nested rule, unchanged, in acreateStaticStylesobject in the same file, merged onto the host element with{...sx(styles.content, fallback.content)}. Put// oxlint-disable-next-line stylex-migration/no-emotion-styles -- <what no prop reaches>above the@lobehub/uiimport. Add a missing slot to lobe-ui instead when the component is ours.
- The component's slot props. lobe-ui components take
Component Priority
src/components— project-specific reusable components
Content truncated.
When not to use it
- →Do not use next/link for SPA navigation
- →Avoid antd Spin component for loading
Prerequisites
Limitations
- →Requires manual sync of desktop variant files
- →Strict import hierarchy must be followed
How it compares
It mandates specific architectural patterns and sync rules for desktop variants that generic React guides do not address.
Compared to similar skills
react side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| react (this skill) | 34 | 5mo | No flags | Intermediate |
| zustand | 113 | 5mo | No flags | Intermediate |
| react-component-patterns | 3 | 4mo | No flags | Intermediate |
| zustand-5 | 8 | 10mo | No flags | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by lobehub
View all by lobehub →You might also like
zustand
lobehub
Zustand state management guide. Use when working with store code (src/store/**), implementing actions, managing state, or creating slices. Triggers on Zustand store development, state management questions, or action implementation.
react-component-patterns
HoangNguyen0403
Modern React component architecture and composition patterns.
zustand-5
prowler-cloud
Zustand 5 state management patterns. Trigger: When implementing client-side state with Zustand (stores, selectors, persist middleware, slices).
1k-state-management
OneKeyHQ
Jotai state management patterns — atoms, globalAtom, contextAtom, and persistence.
react-router-getting-started
ssrjkk
Getting Started for React-Router: initial setup and first steps
accessibility-compliance
wshobson
Implement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.