📃 docs: 补充文档 (#41268)

补充文档

Co-authored-by: chenxiaokun <chenxiaokun@didiglobal.com>
This commit is contained in:
竹雨 2023-03-16 11:50:57 +08:00 committed by GitHub
parent 42d03877c1
commit 272ac40bba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View File

@ -110,3 +110,24 @@ browserHistory.listen(() => {
Modal.destroyAll();
});
```
## FAQ
### Why I can not access context, redux, ConfigProvider `locale/prefixCls` in Modal.xxx?
antd will dynamic create React instance by `ReactDOM.render` when call Modal methods. Whose context is different with origin code located context.
You can try the following ways to solve the problem
set [@ant-prefix](https://github.com/ant-design/ant-design/blob/2c6c789e3a9356f96c47aea0083f5a15538315cf/components/style/themes/default.less#L7)`'ant-prefix': 'antd3'`
```js
import { Modal } from 'antd';
// use
Modal.confirm({
title: 'hello world',
// must use the '-modal' suffix
prefixCls: 'antd3-modal',
});
```

View File

@ -113,3 +113,24 @@ browserHistory.listen(() => {
Modal.destroyAll();
});
```
## FAQ
### 为什么 Modal 方法不能获取 context、redux、的内容和 ConfigProvider `locale/prefixCls` 配置?
直接调用 Modal 方法antd 会通过 `ReactDOM.render` 动态创建新的 React 实体。其 context 与当前代码所在 context 并不相同,因而无法获取 context 信息。
你可以用以下的方法解决这个问题
设置 [@ant-prefix](https://github.com/ant-design/ant-design/blob/2c6c789e3a9356f96c47aea0083f5a15538315cf/components/style/themes/default.less#L7)`'ant-prefix': 'antd3'`
```js
import { Modal } from 'antd';
// 使用
Modal.confirm({
title: 'hello world',
// 必须带上 '-modal' 后缀
prefixCls: 'antd3-modal',
});
```