Skip to content

[email protected]以下无法使用 #596

Closed
@lemonied

Description

@lemonied

重现步骤

在线示例链接:(必填)

https://codesandbox.io/p/sandbox/v554rx

步骤:
使用[email protected]版本,页面直接报错

当前行为

页面报错:
TypeError
Cannot read properties of undefined (reading '_context')

预期行为

页面正常显示

上下文

出于某种特殊的原因,项目的antd无法升级,处于[email protected]较低的版本。

查看antdx的代码时,发现一个hook useInternalToken,这里用到了 antdTheme._internalContext,而_internalContext这个属性在[email protected]才有的;相关commit:ant-design/ant-design@7548dd0

这个报错太不友好了,是不是得把peerDependencies里的antd: >=5.0.0改成 antd: ^5.20.3
不升级antd的情况下,我的解决方法是:

import { theme } from 'antd';
import React from 'react';
if (!(theme as any)._internalContext) {
  (theme as any)._internalContext = React.createContext(theme.defaultConfig);
}

版本

1.0.5

您在哪些浏览器上遇到了这个问题?

Chrome

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions