원클릭으로
react
React 19 最佳實踐指南。當需要撰寫 React 元件、使用 Hooks、處理狀態管理、或搭配 TypeScript/Vite 開發時使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
React 19 最佳實踐指南。當需要撰寫 React 元件、使用 Hooks、處理狀態管理、或搭配 TypeScript/Vite 開發時使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
cubejs (Rubik's Cube solver, Kociemba two-phase) 使用指南。當需要實作魔術方塊自動解法、狀態字串序列化、或 scramble 產生時使用。
msw-fetch-mock 套件使用指南(搭配 MSW v2 + Vitest)。當需要 mock HTTP 請求、測試 fetch 呼叫、驗證 API 互動時使用。
React Three Fiber (R3F) + Three.js + drei 最佳實踐。當需要建立 3D 場景、處理相機/光照、互動事件、動畫、效能優化時使用。
TDD (Test-Driven Development) 最佳實踐指南,搭配 Vitest + React Testing Library。當需要撰寫測試、實踐 Red-Green-Refactor、設計測試結構時使用。應在開發新功能時主動套用。
Test Doubles 最佳實踐指南(Vitest + TypeScript)。當需要選擇 Mock/Stub/Fake/Spy/Dummy、或討論測試隔離策略時使用。
Vite 6/7 最佳實踐指南。當需要初始化 Vite 專案、設定 plugin、配置 build、除錯 HMR、path alias 或整合 React/TS/Vitest 時使用。
| name | react |
| description | React 19 最佳實踐指南。當需要撰寫 React 元件、使用 Hooks、處理狀態管理、或搭配 TypeScript/Vite 開發時使用。 |
基於 2025/5 知識。React 19 已 stable,React Compiler 進入推薦使用。
// 不要用 React.FC(不支援 generics、implicit children)
function Button({ label, onClick }: { label: string; onClick: () => void }) {
return <button onClick={onClick}>{label}</button>
}
// children 明確宣告
type CardProps = { title: string; children: React.ReactNode }
// 抽 props 用 ComponentProps
type InputProps = React.ComponentProps<'input'> & { label: string }
function MyInput({ ref, ...props }: { ref?: React.Ref<HTMLInputElement> } & React.ComponentProps<'input'>) {
return <input ref={ref} {...props} />
}
const [state, formAction, isPending] = useActionState(async (prev, formData) => {
const res = await submit(formData)
return res.error ?? null
}, null)
<form action={formAction}>...</form>
立刻顯示樂觀更新,等 server 回來時 reconcile。
可在 render 中 unwrap Promise 或 Context(Suspense 邊界接):
const data = use(fetchPromise) // 搭配 <Suspense>
const theme = use(ThemeContext)
<Context> 直接當 Provider<ThemeContext value={theme}> {/* 不必 .Provider */}
可以直接在元件內寫 <title>, <meta>, <link>,React 會 hoist 到 head。
不要預防性加。React Compiler 啟用後幾乎都不需要。手動加只在:
開發模式下 effect/state initializer 會跑兩次,是為了暴露不純副作用。cleanup 要寫對才不會 leak。
pnpm add -D babel-plugin-react-compiler
vite.config.ts:
react({ babel: { plugins: ['babel-plugin-react-compiler'] } })
啟用後可刪掉大部分 memo/useMemo/useCallback。
setX({ ...x, a: 1 }) 不是 x.a = 1。async function 再呼叫。