# 错误：上下文提供程序缺少'value'属性。上下文将接收undefined。

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

## 根因

React Context Provider组件在渲染时缺少'value'属性，导致消费组件接收undefined而不是预期的上下文值。

## 版本兼容性

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

## 解决方案

1. ```
   Ensure the Provider component always includes a 'value' prop, even if it's an empty object or a fallback.
   ```
2. ```
   If the value is dynamically computed, use a state variable and pass it as the value prop.
   ```

## 无效尝试

- **Adding a default value to createContext() to avoid undefined** — The default value is only used when there is no Provider at all; if a Provider is present without value, the default is ignored and undefined is passed. (70% 失败率)
- **Wrapping the Provider in a conditional to skip rendering if no value is available** — This may hide the error but leads to missing context for consumers, causing runtime errors later. (60% 失败率)
- **Setting value to null explicitly, thinking it's the same as missing** — null is a valid value and will be passed; the error is specifically about the prop being absent, not its value. (50% 失败率)
