Loading...
Loading...
Compare original and translation side by side
TeamCreateTeamCreate| Hook | Purpose | Guide |
|---|---|---|
| Read promises/context in render | |
| Optimistic UI updates | |
| Form action state management | |
| Form pending state (child components) | |
| Non-reactive callbacks in effects | |
references/new-hooks.md| Hook | 用途 | 指南 |
|---|---|---|
| 在渲染阶段读取Promise/上下文 | |
| 实现乐观UI更新 | |
| 表单动作状态管理 | |
| 表单加载状态(子组件中使用) | |
| 副作用中的非响应式回调 | |
references/new-hooks.md| Hook | Purpose | Guide |
|---|---|---|
| Local component state | |
react-state| Hook | 用途 | 指南 |
|---|---|---|
| 组件本地状态管理 | |
react-state| Hook | Purpose | Guide |
|---|---|---|
| Side effects after paint | |
| Sync DOM before paint | |
| Hook | 用途 | 指南 |
|---|---|---|
| 渲染完成后执行副作用 | |
| 渲染前同步DOM操作 | |
| Hook | Purpose | Guide |
|---|---|---|
| DOM access, mutable values | |
| Customize ref API | |
| Hook | 用途 | 指南 |
|---|---|---|
| DOM访问与可变值存储 | |
| 自定义Ref API | |
| Hook | Purpose | Guide |
|---|---|---|
| Memoize expensive values | |
| Memoize functions | |
| Hook | 用途 | 指南 |
|---|---|---|
| 缓存计算开销大的值 | |
| 缓存函数 | |
| Hook | Purpose | Guide |
|---|---|---|
| Unique IDs for accessibility | |
| External store subscription | |
| Hook | 用途 | 指南 |
|---|---|---|
| 生成无障碍访问所需的唯一ID | |
| 外部状态库订阅 | |
references/custom-hooks-patterns.mdreferences/templates/custom-hooks.mdreferences/custom-hooks-patterns.mdreferences/templates/custom-hooks.md<Activity mode={isActive ? 'visible' : 'hidden'}>
<TabContent />
</Activity>references/activity-component.md<Activity mode={isActive ? 'visible' : 'hidden'}>
<TabContent />
</Activity>references/activity-component.mdreferences/react-compiler.mdreferences/react-compiler.md// Read promise in render (with Suspense)
const data = use(dataPromise)
// Read context conditionally (unique to use())
if (condition) {
const theme = use(ThemeContext)
}references/templates/use-promise.md// 在渲染阶段读取Promise(配合Suspense使用)
const data = use(dataPromise)
// 条件式读取上下文(use()独有的特性)
if (condition) {
const theme = use(ThemeContext)
}references/templates/use-promise.mdconst [optimisticValue, setOptimistic] = useOptimistic(actualValue)
// Update UI immediately, server updates laterreferences/templates/optimistic-update.mdconst [optimisticValue, setOptimistic] = useOptimistic(actualValue)
// 立即更新UI,后续同步服务器数据references/templates/optimistic-update.mdconst [state, action, isPending] = useActionState(asyncFn, initialState)references/templates/action-form.mdconst [state, action, isPending] = useActionState(asyncFn, initialState)references/templates/action-form.mdconst onEvent = useEffectEvent(() => {
// Always has fresh props/state, doesn't trigger re-run
})
useEffect(() => {
connection.on('event', onEvent)
}, []) // No need to add onEvent to depsreferences/new-hooks.mdconst onEvent = useEffectEvent(() => {
// 始终获取最新的props/state,不会触发副作用重跑
})
useEffect(() => {
connection.on('event', onEvent)
}, []) // 无需将onEvent加入依赖数组references/new-hooks.md| Change | Migration |
|---|---|
| Remove |
| Use |
| Import from |
references/migration-18-19.md| 变更内容 | 迁移方案 |
|---|---|
| 移除 |
| 直接使用 |
| 从 |
references/migration-18-19.mduse()useOptimistic<Activity>useEffectEventuse()useOptimistic<Activity>useEffectEvent| Template | Use Case |
|---|---|
| Form with useActionState |
| useOptimistic pattern |
| Activity component tabs |
| use() with promises |
| 模板 | 使用场景 |
|---|---|
| 基于useActionState的表单实现 |
| useOptimistic 实现模式 |
| Activity组件实现标签页 |
| use()配合Promise的实现 |
| Template | Use Case |
|---|---|
| useState patterns |
| useEffect patterns |
| useRef patterns |
| Custom hooks implementations |
| useSyncExternalStore patterns |
| 模板 | 使用场景 |
|---|---|
| useState 实现模式 |
| useEffect 实现模式 |
| useRef 实现模式 |
| 自定义Hooks实现 |
| useSyncExternalStore 实现模式 |
| Template | Use Case |
|---|---|
| TanStack Virtual for long lists |
| Code splitting and lazy loading |
| React DevTools Profiler |
| 模板 | 使用场景 |
|---|---|
| 使用TanStack Virtual实现长列表 |
| 代码分割与懒加载 |
| React DevTools 性能分析 |
references/virtualization.mdreferences/virtualization.mdreferences/lazy-loading.mdreferences/lazy-loading.mdreferences/profiling.mdreferences/profiling.mduseEffectuse()forwardRefref<Context.Provider><Context value={}><Activity>useEffectuse()forwardRefref<Context.Provider><Context value={}><Activity>