From 272ac40bba66cbd838c210c41f8afd7060712e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=B9=E9=9B=A8?= <34495411+cxk0831@users.noreply.github.com> Date: Thu, 16 Mar 2023 11:50:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=83=20docs:=20=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E6=96=87=E6=A1=A3=20(#41268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补充文档 Co-authored-by: chenxiaokun --- components/modal/index.en-US.md | 21 +++++++++++++++++++++ components/modal/index.zh-CN.md | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/components/modal/index.en-US.md b/components/modal/index.en-US.md index 3a98feb568..8559b11303 100644 --- a/components/modal/index.en-US.md +++ b/components/modal/index.en-US.md @@ -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', +}); +``` diff --git a/components/modal/index.zh-CN.md b/components/modal/index.zh-CN.md index d81b9fe06d..65f3f236ad 100644 --- a/components/modal/index.zh-CN.md +++ b/components/modal/index.zh-CN.md @@ -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', +}); +```