You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Reactstrap项目添加Button时报错:Cannot read properties of null (reading 'useCallback')

解决reactstrap Button组件导致的"Cannot read properties of null (reading 'useCallback')"报错

这个报错通常是reactstrap与React版本不兼容或依赖安装不完整/冲突导致的,按以下步骤排查解决:

1. 确保reactstrap与React版本兼容并重新安装依赖

reactstrap v9+ 需要React 16.8+(支持Hooks的版本),如果你的React版本符合要求,先卸载现有reactstrap并重新安装兼容版本:

npm uninstall reactstrap
npm install reactstrap bootstrap@5

注:reactstrap v9依赖Bootstrap 5,安装后需在index.js中引入Bootstrap CSS,否则组件样式会异常:

import 'bootstrap/dist/css/bootstrap.min.css';

2. 升级React和ReactDOM到最新稳定版

如果你的React版本低于16.8,或版本过旧引发兼容性问题,执行升级命令:

npm install react@latest react-dom@latest

3. 清理依赖缓存并重新安装

若存在重复React包或依赖冲突,删除现有依赖文件后重新安装:

# Windows系统替换为:rmdir /s/q node_modules && del package-lock.json
rm -rf node_modules package-lock.json
npm install

4. 逐步排查组件冲突

暂时注释掉<ContextBody/>组件,验证是否是该组件与Button存在逻辑冲突,再逐步恢复代码定位问题。

按以上步骤操作后重启项目,即可解决该报错。

内容的提问来源于stack exchange,提问作者ACCE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 23:51:07