# 类型错误：无法读取 null 的属性（读取 'useCallback'）

- **ID:** `react/cannot-read-properties-of-null-reading-usecallback`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

React hooks（如 useCallback）在有效的 React 组件或自定义 Hook 上下文之外被调用，通常是由于模块打包错误或 React 导入不正确。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| React 18.2.0 | active | — | — |
| React 19.0.0 | active | — | — |
| Webpack 5.88.0 | active | — | — |
| Node 20.11.0 | active | — | — |

## 解决方案

1. ```
   Ensure React is imported correctly at the top of the file: `import React, { useCallback } from 'react';` and check that your bundler (e.g., webpack) resolves 'react' to a valid module.
   ```
2. ```
   If using webpack, add an alias for 'react' in webpack.config.js: `resolve: { alias: { react: path.resolve('./node_modules/react') } }` to force correct resolution.
   ```
3. ```
   Check for multiple React versions in node_modules (e.g., from hoisting issues). Run `npm ls react` or `yarn why react` and deduplicate using `npm dedupe` or resolutions in package.json.
   ```

## 无效尝试

- **** — The error is about React object being null, not strict mode. (95% 失败率)
- **** — The issue is with module resolution, not JSX structure. (90% 失败率)
- **** — The error stems from bundler misconfiguration, not corrupted packages. (80% 失败率)
