Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计通过

docs-sandpack文档沙包

Agent Skill

用于辅助文档、README、Markdown、说明文和内容稿件的整理与改写。它适合让 Agent 提炼结构、补齐章节、统一术语、检查链接或把零散材料整理成可读文档。使用时应保留项目已有事实、命令和路径,不要把未确认的信息写成确定结论;涉及对外文案时,还需要控制语气,避免过度营销或夸大能力。

总安装

1,360

周安装

55

GitHub Stars

11,719

下载量

427
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:docs-sandpack(文档沙包)
来源仓库:https://github.com/reactjs/react.dev
仓库路径:skills/docs-sandpack
安装命令:
npx skills add https://github.com/reactjs/react.dev --skill docs-sandpack
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/reactjs/react.dev --skill docs-sandpack

简介

提供标准化的 Sandpack 代码沙箱示例编写指导。

  • 支持单文件或多文件结构的交互式代码演示创建。docs-sandpack 属于开发类 Skill,可作为该场景下的辅助能力补充。
  • 定义主文件命名规则、隐藏文件标识及 CSS 样式引用方式。
  • 强调 package.json 中依赖声明的必要性以避免运行时错误。
  • 适用于 React 官方文档及其他需要嵌入可运行代码片段的场景。

SKILL.md

Sandpack Patterns

Quick Start Template

Most examples are single-file. Copy this and modify:

<Sandpack>

` ` `js
import { useState } from 'react';

export default function Example() {
  const [value, setValue] = useState(0);

  return (
    <button onClick={() => setValue(value + 1)}>
      Clicked {value} times
    </button>
  );
}
` ` `

</Sandpack>

File Naming

PatternUsage
``` `js ```Main file (no prefix)
``` `js src/FileName.js ```Supporting files
``` `js src/File.js active ```Active file (reference pages)
``` `js src/data.js hidden ```Hidden files
``` `css ```CSS styles
``` `json package.json ```External dependencies

Critical: Main file must have export default.

Line Highlighting

function Example() { // Lines 2-4 // will be // highlighted return null; }


## Code References (numbered callouts)
// Creates numbered markers pointing to "age" and "setAge" on line 4

Expected Errors (intentionally broken examples)

// Line 7 shows as expected error


## Multi-File Example

<Sandpack>

import Gallery from './Gallery.js';

export default function App() {
  return <Gallery />;
}
export default function Gallery() {
  return <h1>Gallery</h1>;
}
h1 { color: purple; }

External Dependencies

<Sandpack>

import { useImmer } from 'use-immer'; // ...

{ "dependencies": { "immer": "1.7.3", "use-immer": "0.5.1", "react": "latest", "react-dom": "latest", "react-scripts": "latest" } }


## Code Style in Sandpack (Required)

Sandpack examples are held to strict code style standards:

1. **Function declarations** for components (not arrows)
2. **`e`** for event parameters
3. **Single quotes** in JSX
4. **`const`** unless reassignment needed
5. **Spaces in destructuring**: `({props})` not `({props})`
6. **Two-line createRoot**: separate declaration and render call
7. **Multiline if statements**: always use braces

### Don't Create Hydration Mismatches

Sandpack examples must produce the same output on server and client:

// 🚫 This will cause hydration warnings export default function App() { const isClient = typeof window !== 'undefined'; return <div>{isClient ? 'Client' : 'Server'}</div>; }


### Use Ref for Non-Rendered State

// 🚫 Don't trigger re-renders for non-visual state const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []);

// ✅ Use ref instead const mounted = useRef(false); useEffect(() => { mounted.current = true; }, []);


## forwardRef and memo Patterns

### forwardRef - Use Named Function

// ✅ Named function for DevTools display name const MyInput = forwardRef(function MyInput(props, ref) { return <input {...props} ref={ref} />; });

// 🚫 Anonymous loses name const MyInput = forwardRef((props, ref) => { ... });


### memo - Use Named Function

// ✅ Preserves component name const Greeting = memo(function Greeting({ name }) { return <h1>Hello, {name}</h1>; });


## Line Length

- Prose: ~80 characters
- Code: ~60-70 characters
- Break long lines to avoid horizontal scrolling

## Anti-Patterns

| Pattern | Problem | Fix |
| --- | --- | --- |
| `const Comp = () => {}` | Not standard | `function Comp() {}` |
| `onClick={(event) =>...}` | Conflicts with global | `onClick={(e) =>...}` |
| `useState` for non-rendered values | Re-renders | Use `useRef` |
| Reading `window` during render | Hydration mismatch | Check in useEffect |
| Single-line if without braces | Harder to debug | Use multiline with braces |
| Chained `createRoot().render()` | Less clear | Two statements |
| `//...` without space | Inconsistent | `//...` with space |
| Tabs | Inconsistent | 2 spaces |
| `ReactDOM.render` | Deprecated | Use `createRoot` |
| Fake package names | Confusing | Use `'./your-storage-layer'` |
| `PropsWithChildren` | Outdated | `children?: ReactNode` |
| Missing `key` in lists | Warnings | Always include key |

## Additional Code Quality Rules

### Always Include Keys in Lists

// ✅ Correct {items.map(item => <li key={item.id}>{item.name}</li>)}

// 🚫 Wrong - missing key {items.map(item => <li>{item.name}</li>)}


### Use Realistic Import Paths

// ✅ Correct - descriptive path import { fetchData } from './your-data-layer';

// 🚫 Wrong - looks like a real npm package import { fetchData } from 'cool-data-lib';


### Console.log Labels

// ✅ Correct - labeled for clarity console.log('User:', user); console.log('Component Stack:', errorInfo.componentStack);

// 🚫 Wrong - unlabeled console.log(user);


### Keep Delays Reasonable

// ✅ Correct - 1-1.5 seconds setTimeout(() => setLoading(false), 1000);

// 🚫 Wrong - too long, feels sluggish setTimeout(() => setLoading(false), 3000);


## Updating Line Highlights

When modifying code in examples with line highlights (`{2-4}`), **always update the highlight line numbers** to match the new code. Incorrect line numbers cause rendering crashes.

## File Name Conventions

- Capitalize file names for component files: `Gallery.js` not `gallery.js`
- After initially explaining files are in `src/`, refer to files by name only: `Gallery.js` not `src/Gallery.js`

## Naming Conventions in Code

**Components:** PascalCase

- `Profile`, `Avatar`, `TodoList`, `PackingList`

**State variables:** Destructured pattern

- `const [count, setCount] = useState(0)`
- Booleans: `[isOnline, setIsOnline]`, `[isPacked, setIsPacked]`
- Status strings: `'typing'`, `'submitting'`, `'success'`, `'error'`

**Event handlers:**

- `handleClick`, `handleSubmit`, `handleAddTask`

**Props for callbacks:**

- `onClick`, `onChange`, `onAddTask`, `onSelect`

**Custom Hooks:**

- `useOnlineStatus`, `useChatRoom`, `useFormInput`

**Reducer actions:**

- Past tense: `'added'`, `'changed'`, `'deleted'`
- Snake_case compounds: `'changed_selection'`, `'sent_message'`

**Updater functions:** Single letter

- `setCount(n => n + 1)`

### Pedagogical Code Markers

**Wrong vs right code:**

// 🔴 Avoid: redundant state and unnecessary Effect // ✅ Good: calculated during rendering


**Console.log for lifecycle teaching:**

console.log('✅ Connecting...'); console.log('❌ Disconnected.');


### Server/Client Labeling

// Server Component async function Notes() { const notes = await db.notes.getAll(); }

// Client Component "use client" export default function Expandable({children}) { const [expanded, setExpanded] = useState(false); }


### Bundle Size Annotations

import marked from 'marked'; // 35.9K (11.2K gzipped) import sanitizeHtml from 'sanitize-html'; // 206K (63.3K gzipped)


---

## Sandpack Example Guidelines

### Package.json Rules

**Include package.json when:**

- Using external npm packages (immer, remarkable, leaflet, toastify-js, etc.)
- Demonstrating experimental/canary React features
- Requiring specific React versions (`react: beta`, `react: 19.0.0-rc-*`)

**Omit package.json when:**

- Example uses only built-in React features
- No external dependencies needed
- Teaching basic hooks, state, or components

**Always mark package.json as hidden:**
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "react-scripts": "latest",
    "immer": "1.7.3"
  }
}
**Version conventions:**
- Use `"latest"` for stable features
- Use exact versions only when compatibility requires it
- Include minimal dependencies (just what the example needs)

### Hidden File Patterns

**Always hide these file types:**

| File Type | Reason |
|-----------|--------|
| `package.json` | Configuration not the teaching point |
| `sandbox.config.json` | Sandbox setup is boilerplate |
| `public/index.html` | HTML structure not the focus |
| `src/data.js` | When it contains sample/mock data |
| `src/api.js` | When showing API usage, not implementation |
| `src/styles.css` | When styling is not the lesson |
| `src/router.js` | Supporting infrastructure |
| `src/actions.js` | Server action implementation details |

**Rationale:**
- Reduces cognitive load
- Keeps focus on the primary concept
- Creates cleaner, more focused examples

**Example:**
export const items = [
  { id: 1, name: 'Item 1' },
  { id: 2, name: 'Item 2' },
];
### Active File Patterns

**Mark as active when:**
- File contains the primary teaching concept
- Learner should focus on this code first
- Component demonstrates the hook/pattern being taught

**Effect of the `active` marker:**
- Sets initial editor tab focus when Sandpack loads
- Signals "this is what you should study"
- Works with hidden files to create focused examples

**Most common active file:** `src/index.js` or `src/App.js`

**Example:**
// This file will be focused when example loads
export default function App() {
  // ...
}
### File Structure Guidelines

| Scenario | Structure | Reason |
|----------|-----------|--------|
| Basic hook usage | Single file | Simple, focused |
| Teaching imports | 2-3 files | Shows modularity |
| Context patterns | 4-5 files | Realistic structure |
| Complex state | 3+ files | Separation of concerns |

**Single File Examples (70% of cases):**
- Use for simple concepts
- 50-200 lines typical
- Best for: Counter, text inputs, basic hooks

**Multi-File Examples (30% of cases):**
- Use when teaching modularity/imports
- Use for context patterns (4-5 files)
- Use when component is reused

**File Naming:**
- Main component: `App.js` (capitalized)
- Component files: `Gallery.js`, `Button.js` (capitalized)
- Data files: `data.js` (lowercase)
- Utility files: `utils.js` (lowercase)
- Context files: `TasksContext.js` (named after what they provide)

### Code Size Limits

- Single file: **<200 lines**
- Multi-file total: **150-300 lines**
- Main component: **100-150 lines**
- Supporting files: **20-40 lines each**

### CSS Guidelines

**Always:**
- Include minimal CSS for demo interactivity
- Use semantic class names (`.panel`, `.button-primary`, `.panel-dark`)
- Support light/dark themes when showing UI concepts
- Keep CSS visible (never hidden)

**Size Guidelines:**
- Minimal (5-10 lines): Basic button styling, spacing
- Medium (15-30 lines): Panel styling, form layouts
- Complex (40+ lines): Only for layout-focused examples

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.39%
按下载量换算155

Claude

31.53%
按下载量换算135

Cursor

18.28%
按下载量换算78

Gemini CLI

10.46%
按下载量换算45

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills