# 错误：元素类型无效：期望一个字符串（用于内置组件）或一个类/函数（用于复合组件），但得到了对象。请检查 `App` 的 render 方法。

- **ID:** `react/invalid-array-child`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

组件的 render 方法返回了一个包含非 React 元素对象的数组，例如纯 JavaScript 对象或未渲染的组件类，而不是有效的 React 元素。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| React 16.8+ | active | — | — |
| React 17.0.2 | active | — | — |
| React 18.2.0 | active | — | — |

## 解决方案

1. ```
   If you meant to render a list of components, ensure each item is a React element: data.map(item => <Component key={item.id} />). If you meant to display an object, use JSON.stringify(object) or access specific properties.
   ```
2. ```
   Check that you are not accidentally passing a component class instead of an instance: <Component /> not Component alone.
   ```

## 无效尝试

- **Wrapping the object in a <div> or fragment** — If the object is not a valid React element, wrapping it won't fix the underlying issue—it will just produce a different error or render nothing. (40% 失败率)
- **Using JSON.stringify on the object** — This converts the object to a string, which may be displayed but is not a valid React child and can cause hydration mismatches. (60% 失败率)
- **Importing the component as default instead of named** — If the object is a plain JS object (e.g., from an API), no import style will make it a valid component. (50% 失败率)
