preact — for Claude Code preact, modular-frontend-architecture, community, for Claude Code, ide skills, resolve-library-id, "preact", get-library-docs, forwardRef, ui-components

v1.0

关于此技能

适用场景: Ideal for AI agents that need context7 — live docs. 本地化技能摘要: A reference architecture for building modular React frontends using a monorepo setup, Rsbuild/Rslib, Module Federation, and import maps. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

功能特性

Context7 — Live Docs
Before implementing, fetch current docs via Context7 MCP to avoid stale APIs:
resolve-library-id → "preact"
get-library-docs with resolved ID + your specific topic
Writing Preact functional components or custom hooks

# 核心主题

Hyperxq Hyperxq
[0]
[0]
更新于: 4/3/2026

Killer-Skills Review

Decision support comes first. Repository text comes second.

Reference-Only Page Review Score: 10/11

This page remains useful for teams, but Killer-Skills treats it as reference material instead of a primary organic landing page.

Original recommendation layer Concrete use-case guidance Explicit limitations and caution Quality floor passed for review
Review Score
10/11
Quality Score
75
Canonical Locale
en
Detected Body Locale
en

适用场景: Ideal for AI agents that need context7 — live docs. 本地化技能摘要: A reference architecture for building modular React frontends using a monorepo setup, Rsbuild/Rslib, Module Federation, and import maps. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

核心价值

推荐说明: preact helps agents context7 — live docs. A reference architecture for building modular React frontends using a monorepo setup, Rsbuild/Rslib, Module Federation, and import maps. This AI agent skill supports

适用 Agent 类型

适用场景: Ideal for AI agents that need context7 — live docs.

赋予的主要能力 · preact

适用任务: Applying Context7 — Live Docs
适用任务: Applying Before implementing, fetch current docs via Context7 MCP to avoid stale APIs:
适用任务: Applying resolve-library-id → "preact"

! 使用限制与门槛

  • 限制说明: Before implementing, fetch current docs via Context7 MCP to avoid stale APIs:
  • 限制说明: ui-components — display only
  • 限制说明: Need global app state? → Zustand store in shell, passed as prop to component

Why this page is reference-only

  • - Current locale does not satisfy the locale-governance contract.

Source Boundary

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

评审后的下一步

先决定动作,再继续看上游仓库材料

Killer-Skills 的主价值不应该停在“帮你打开仓库说明”,而是先帮你判断这项技能是否值得安装、是否应该回到可信集合复核,以及是否已经进入工作流落地阶段。

实验室 Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

常见问题与安装步骤

以下问题与步骤与页面结构化数据保持一致,便于搜索引擎理解页面内容。

? FAQ

preact 是什么?

适用场景: Ideal for AI agents that need context7 — live docs. 本地化技能摘要: A reference architecture for building modular React frontends using a monorepo setup, Rsbuild/Rslib, Module Federation, and import maps. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

如何安装 preact?

运行命令:npx killer-skills add Hyperxq/modular-frontend-architecture/preact。支持 Cursor、Windsurf、VS Code、Claude Code 等 19+ IDE/Agent。

preact 适用于哪些场景?

典型场景包括:适用任务: Applying Context7 — Live Docs、适用任务: Applying Before implementing, fetch current docs via Context7 MCP to avoid stale APIs:、适用任务: Applying resolve-library-id → "preact"。

preact 支持哪些 IDE 或 Agent?

该技能兼容 Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer。可使用 Killer-Skills CLI 一条命令通用安装。

preact 有哪些限制?

限制说明: Before implementing, fetch current docs via Context7 MCP to avoid stale APIs:;限制说明: ui-components — display only;限制说明: Need global app state? → Zustand store in shell, passed as prop to component。

安装步骤

  1. 1. 打开终端

    在你的项目目录中打开终端或命令行。

  2. 2. 执行安装命令

    运行:npx killer-skills add Hyperxq/modular-frontend-architecture/preact。CLI 会自动识别 IDE 或 AI Agent 并完成配置。

  3. 3. 开始使用技能

    preact 已启用,可立即在当前项目中调用。

! 参考页模式

此页面仍可作为安装与查阅参考,但 Killer-Skills 不再把它视为主要可索引落地页。请优先阅读上方评审结论,再决定是否继续查看上游仓库说明。

Upstream Repository Material

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

Upstream Source

preact

A reference architecture for building modular React frontends using a monorepo setup, Rsbuild/Rslib, Module Federation, and import maps. This AI agent skill

SKILL.md
Readonly
Upstream Repository Material
The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.
Supporting Evidence

Context7 — Live Docs

Before implementing, fetch current docs via Context7 MCP to avoid stale APIs:

  1. resolve-library-id"preact"
  2. get-library-docs with resolved ID + your specific topic

When to Use

  • Writing Preact functional components or custom hooks
  • Importing hooks, types, or JSX utilities
  • Configuring Rsbuild / Rslib / Rstest for Preact
  • Setting up Module Federation shared config
  • Using forwardRef or any compat bridge
  • Reviewing or fixing JSX transform issues

Architecture Rules (READ BEFORE WRITING ANY COMPONENT)

This project has a strict separation between shell (smart) and ui-components (dumb).

ui-components — display only

  • NEVER import or create Zustand stores
  • NEVER add business logic, auth, routing, or A/B testing
  • MAY consume React Context — but the Provider ALWAYS lives in shell
  • Receives ALL data and callbacks via props or context from shell
  • All dependencies are peerDependencies — the component output bundles NOTHING

shell — smart layer

  • Owns Zustand stores, Context providers, auth, routing, business logic
  • Reads from Zustand, passes data DOWN to ui-components via props or context
  • Never lets ui-components reach back up for data

State decision tree

Need global app state?          → Zustand store in shell, passed as prop to component
Need to share across subtree?   → Context provider in shell, useContext in component
Need local UI state?            → useState / useReducer inside the component (fine in ui-components)
Need to trigger app logic?      → Callback prop passed from shell to component

Critical Patterns

1. tsconfig — ALWAYS jsxImportSource: preact

Every tsconfig.json in the monorepo must include:

json
1{ 2 "compilerOptions": { 3 "jsx": "react-jsx", 4 "jsxImportSource": "preact" 5 } 6}

Never use "jsxImportSource": "react". This project does NOT import the React namespace.


2. Imports — source of truth

ts
1// ✅ Hooks → preact/hooks 2import { useState, useEffect, useRef, useCallback, useMemo, useReducer, useContext, createContext } from "preact/hooks"; 3 4// ✅ Core types and primitives → preact 5import { h, Fragment, createRef, cloneElement } from "preact"; 6import type { FunctionalComponent, ComponentChildren, VNode, RefObject } from "preact"; 7 8// ✅ forwardRef, memo, lazy, Suspense → preact/compat 9import { forwardRef, memo, lazy, Suspense } from "preact/compat"; 10 11// ❌ NEVER — even though react is aliased, don't import it directly 12import React from "react"; 13import { useState } from "react"; 14import type { FC } from "react";

3. Functional Component pattern

tsx
1import type { FunctionalComponent, ComponentChildren } from "preact"; 2import { useState } from "preact/hooks"; 3 4interface CardProps { 5 title: string; 6 children: ComponentChildren; 7 onClose?: () => void; 8} 9 10export const Card: FunctionalComponent<CardProps> = ({ title, children, onClose }) => { 11 const [open, setOpen] = useState(true); 12 13 if (!open) return null; 14 15 return ( 16 <div className="card"> 17 <h2>{title}</h2> 18 <div>{children}</div> 19 {onClose && ( 20 <button type="button" onClick={() => { setOpen(false); onClose(); }}> 21 Close 22 </button> 23 )} 24 </div> 25 ); 26};

4. Hooks pattern

tsx
1import { useState, useEffect, useRef, useCallback } from "preact/hooks"; 2import type { RefObject } from "preact"; 3 4export function useDebounce<T>(value: T, delay: number): T { 5 const [debounced, setDebounced] = useState<T>(value); 6 7 useEffect(() => { 8 const timer = setTimeout(() => setDebounced(value), delay); 9 return () => clearTimeout(timer); 10 }, [value, delay]); 11 12 return debounced; 13} 14 15// useRef with type 16const inputRef: RefObject<HTMLInputElement> = useRef<HTMLInputElement>(null);

5. forwardRef pattern

tsx
1import { forwardRef } from "preact/compat"; 2import type { Ref } from "preact"; 3 4interface InputProps { 5 label: string; 6 value: string; 7 onChange: (value: string) => void; 8} 9 10export const Input = forwardRef<HTMLInputElement, InputProps>( 11 ({ label, value, onChange }, ref) => ( 12 <label> 13 {label} 14 <input 15 ref={ref} 16 value={value} 17 onInput={(e) => onChange((e.target as HTMLInputElement).value)} 18 /> 19 </label> 20 ) 21);

6. Signals (optional, if @preact/signals is installed)

ts
1import { signal, computed, effect } from "@preact/signals"; 2 3const count = signal(0); 4const doubled = computed(() => count.value * 2); 5 6effect(() => { 7 console.log("count changed:", count.value); 8}); 9 10// In component — signal auto-subscribes on read 11export const Counter: FunctionalComponent = () => ( 12 <button type="button" onClick={() => count.value++}> 13 {count} × 2 = {doubled} 14 </button> 15);

Types Reference

TypeFromUsage
FunctionalComponent<P>preactFunction components (replaces React.FC)
ComponentChildrenpreactchildren prop type (replaces React.ReactNode)
VNodepreactJSX element return type
RefObject<T>preactReturn type of useRef<T>()
JSX.CSSPropertiespreactInline style object (replaces React.CSSProperties)
Ref<T>preactAccepts both callback refs and RefObject<T>
ComponentType<P>preactUnion of FC and class component types

Key Differences from React

ReactPreact equivalent
React.FC<P>FunctionalComponent<P> from preact
React.ReactNodeComponentChildren from preact
React.CSSPropertiesJSX.CSSProperties from preact
import { useState } from "react"import { useState } from "preact/hooks"
import { forwardRef } from "react"import { forwardRef } from "preact/compat"
class attributeBoth class and className work (compat normalizes)
React.createElementh from preact (but rarely needed directly)
React.FragmentFragment from preact or <>...</> shorthand

Module Federation — Singleton (CRITICAL)

Preact must be configured as singleton in all MF hosts and remotes. Duplicate Preact runtimes cause hooks to silently break.

ts
1// rsbuild.config.ts / rslib.config.ts 2import { pluginModuleFederation } from "@module-federation/rsbuild-plugin"; 3 4export default { 5 plugins: [ 6 pluginModuleFederation({ 7 name: "my_app", 8 shared: { 9 preact: { 10 singleton: true, 11 requiredVersion: "^10.0.0", 12 }, 13 "preact/hooks": { 14 singleton: true, 15 requiredVersion: "^10.0.0", 16 }, 17 "preact/compat": { 18 singleton: true, 19 requiredVersion: "^10.0.0", 20 }, 21 "preact/jsx-runtime": { 22 singleton: true, 23 requiredVersion: "^10.0.0", 24 }, 25 }, 26 }), 27 ], 28};

Build Config — pluginPreact() is mandatory

pluginPreact() must be present in every rsbuild.config.ts, rslib.config.ts, and rstest.config.ts. Without it, JSX transform breaks and HMR won't work correctly.

ts
1// rsbuild.config.ts 2import { defineConfig } from "@rsbuild/core"; 3import { pluginPreact } from "@rsbuild/plugin-preact"; 4 5export default defineConfig({ 6 plugins: [pluginPreact()], 7});
ts
1// rstest.config.ts 2import { defineConfig } from "@rstest/core"; 3import { pluginPreact } from "@rsbuild/plugin-preact"; 4 5export default defineConfig({ 6 plugins: [pluginPreact()], 7 // ... test config 8});

Commands

bash
1bun run dev # dev server with Preact HMR 2bun run test # runs rstest with pluginPreact() 3bun run build # rslib/rsbuild build with Preact 4bun run typecheck # tsc --noEmit — validates jsxImportSource

Suspense + Refs — Critical Timing Gotcha

NEVER place a ref target element inside a <Suspense> boundary if a hook in the parent component depends on that ref in a useEffect.

When a component wraps lazy children in <Suspense>, the children don't exist in the DOM until the lazy imports resolve. But the parent's useEffect runs immediately on mount — when ref.current is still null. Since ref is a stable object identity, the effect never re-runs, and any hook that attaches listeners or observers (useSwipe, useFocusTrap, useClickOutside, IntersectionObserver, ResizeObserver, etc.) silently fails with zero errors.

tsx
1// ❌ BAD — ref is null when useEffect runs, listeners never attached 2const MyComponent: FunctionalComponent = () => { 3 const contentRef = useRef<HTMLDivElement>(null); 4 useSwipe(contentRef, { onSwipeLeft: goNext }); // effect runs, ref.current is null → silent no-op 5 6 return ( 7 <Suspense fallback={<Skeleton />}> 8 <LazyChild> 9 <div ref={contentRef}>content</div> {/* doesn't exist until lazy resolves */} 10 </LazyChild> 11 </Suspense> 12 ); 13}; 14 15// ✅ GOOD — ref target is outside Suspense, available immediately 16const MyComponent: FunctionalComponent = () => { 17 const contentRef = useRef<HTMLDivElement>(null); 18 useSwipe(contentRef, { onSwipeLeft: goNext }); // effect runs, ref.current exists ✓ 19 20 return ( 21 <div ref={contentRef}> {/* exists on mount, events from children bubble up */} 22 <Suspense fallback={<Skeleton />}> 23 <LazyChild>content</LazyChild> 24 </Suspense> 25 </div> 26 ); 27};

Key points:

  • Suspense can wrap multiple lazy components (one skeleton for all is fine)
  • Only ref targets that hooks depend on need to be outside the boundary
  • Child DOM events (touch, click, keyboard) naturally bubble up to the parent ref element
  • This bug is completely silent — no errors, no warnings, the feature just doesn't work

Common Mistakes to Avoid

  • Importing hooks from "react" — fails silently or throws; always use "preact/hooks"
  • Missing pluginPreact() in rstest — tests can't parse JSX
  • Duplicate Preact in MF — hooks state is lost across remote boundary; always singleton: true
  • Using React.FC — use FunctionalComponent<P> from preact instead
  • jsxImportSource: "react" in any tsconfig — breaks the entire JSX transform for that package
  • Ref target inside <Suspense> — ref is null when useEffect runs; listeners never attached (see section above)

相关技能

寻找 preact 的替代方案 (Alternative) 或可搭配使用的同类 community Skill?探索以下相关开源技能。

查看全部

openclaw-release-maintainer

Logo of openclaw
openclaw

Your own personal AI assistant. Any OS. Any Platform. The lobster way. 🦞

333.8k
0
AI

widget-generator

Logo of f
f

为prompts.chat的信息反馈系统生成可定制的插件小部件

149.6k
0
AI

flags

Logo of vercel
vercel

React 框架

138.4k
0
浏览器

pr-review

Logo of pytorch
pytorch

Python中具有强大GPU加速的张量和动态神经网络

98.6k
0
开发者工具