# 警告：forwardRef 渲染函数只接受两个参数：props 和 ref。你是否意外地将 children 作为单独的参数传递了？

- **ID:** `react/forwardref-children-prop`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

使用 React.forwardRef 时，渲染函数签名是 (props, ref) => JSX。将 children 作为第三个参数传递或错误解构 ref 会导致此警告，常见于包装一个期望 children 作为 prop 的组件时。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| React 16.8+ | active | — | — |
| React 17.x | active | — | — |
| React 18.x | active | — | — |

## 解决方案

1. ```
   Ensure the forwardRef callback has exactly two parameters: props and ref. Access children via props.children. Example: const MyComponent = React.forwardRef((props, ref) => <div ref={ref}>{props.children}</div>);
   ```
2. ```
   If using TypeScript, define the component with React.PropsWithChildren<P> and forwardRef: const MyComponent = React.forwardRef<HTMLDivElement, React.PropsWithChildren<{}>>((props, ref) => ...);
   ```
3. ```
   For class components, avoid forwardRef and use a callback ref pattern: <div ref={(node) => { this.myRef = node; }}>
   ```

## 无效尝试

- **** — React's forwardRef only passes two arguments; the third parameter is always undefined. (95% 失败率)
- **** — React does not pass ref through props; it's a separate argument. This breaks ref forwarding. (85% 失败率)
- **** — Overcomplicates the component hierarchy without fixing the forwardRef signature mismatch. (70% 失败率)
