用途:在编写 TypeScript React 组件、为 Hook/事件/表单/ref 标注类型,或使用 React 19 新特性与类型安全路由时提供指导。适用范围为非 React TypeScript 或纯 JS React 之外的类型化 React 开发。
主要能力:组件 props 通过 ComponentPropsWithoutRef 扩展原生元素;children 使用 ReactNode;变体 props 用可辨识联合。事件处理使用具体事件类型(如 React.MouseEvent、React.ChangeEvent)。Hook 类型:useState 对联合类型/null 显式标注,useRef 区分 DOM 与可变值,useReducer 用可辨识联合 action,自定义 Hook 用 as const 返回元组,useContext 配 null 守卫。支持泛型组件(如 Table 依据 keyof T 推断)。
React 19 变更:ref 作为普通 prop(不再用 forwardRef);useActionState 替代 useFormState;use() 解包 promise/context;Server Components 可异步、Server Actions 用 'use server',客户端用 useActionState 连接。
路由:TanStack Router 配合 Zod 做编译期类型安全与搜索参数校验;React Router v7 用 Framework Mode 自动类型生成,loader/action 与组件 props 类型联动。
限制与禁用项:不要用 any 标注事件处理器,不用 JSX.Element 作 children,React 19+ 不用 forwardRef,不使用已弃用的 useFormState,注意 DOM ref 的 null 处理,避免同文件混用 Server/Client 组件,传给 use() 的 promise 不要提前 await。资料未提供收费、价格或安装命令等信息。