# 类型错误：无法读取 undefined 的属性（读取 'value'）在访问 context 时

- **ID:** `react/context-value-undefined-in-provider`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 94%

## 根因

一个组件使用 useContext 消费 context，但相应的 Provider 缺失，或者 Provider 没有提供 'value' prop，导致 context 值为 undefined。

## 版本兼容性

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

## 解决方案

1. ```
   Ensure the component consuming the context is wrapped in the corresponding Provider component with a 'value' prop.
   ```
2. ```
   Add a null/undefined check before accessing properties on the context value to provide a fallback UI or default value.
   ```

## 无效尝试

- **** — If the consumer tries to access nested properties that aren't in the default value, it still throws undefined errors. (60% 失败率)
- **** — Even if the Provider is present, importing a different context instance means the consumer doesn't see the provided value. (75% 失败率)
