# 警告：forwardRef 渲染函数只接受两个参数：props 和 ref。您是否打算使用 React.forwardRef？

- **ID:** `react/forwardref-params-error`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

函数组件在使用 forwardRef 时定义了超过两个参数（例如 props、ref、extraParam），但 forwardRef 期望正好两个参数。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| react@18.2.0 | active | — | — |
| react-dom@18.2.0 | active | — | — |

## 解决方案

1. ```
   Remove the extra parameter and use props object directly: `const MyComponent = React.forwardRef((props, ref) => { const { extraParam, ...rest } = props; return <div ref={ref}>...</div>; });`
   ```
2. ```
   If you need additional parameters, pass them via props: `<MyComponent extraParam={value} />` and access `props.extraParam` inside the forwardRef function.
   ```

## 无效尝试

- **Ignoring the warning and passing extra parameters anyway** — React will ignore the extra parameters, and the component may not behave as expected. (80% 失败率)
- **Using a class component instead of a function component with forwardRef** — Class components handle refs differently; you may lose the benefits of forwardRef or cause other errors. (50% 失败率)
- **Wrapping the component in another HOC that passes extra props** — This adds complexity without fixing the root cause; the extra parameter is still passed to the forwardRef function. (60% 失败率)
