Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add global message use case #48167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

shezhangzhang
Copy link
Contributor

@shezhangzhang shezhangzhang commented Mar 29, 2024

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

CN:
文档中的全局使用 message 用例不够全面。在纯 JS/TS 中使用全局 message 这种场景非常常见,按照现有文档中的写法,用户自己做出来比较困难,需要增加例子引导。
EN:
The use of the global message in the document is not comprehensive enough. The scenario of using the global message in pure JS/TS is very common. According to the current document, it is difficult for users to do it themselves, and examples need to be added for users.

📝 Changelog

Language Changelog
🇺🇸 English Added document examples of global use of message, and added top-level registration links in the message and notification documents.
🇨🇳 Chinese 增加了全局使用 message 的文档例子,在 messagenotification 的文档中加入了顶层注册的跳转链接。

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

stackblitz bot commented Mar 29, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Mar 29, 2024

Preview is ready

Copy link
Contributor

github-actions bot commented Mar 29, 2024

👁 Visual Regression Report for PR #48167 Passed ✅

🎯 Target branch: master (9ccb419)
📖 View Full Report ↗︎

🎊 Congrats! No visual-regression diff found.

@@ -122,6 +122,76 @@ export default () => {
};
```

### 全局 JS/TS 使用场景
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全局 redux 示例已经有过了,再写一个额外的感觉没什么必要。

https://ant-design.antgroup.com/components/app-cn#%E5%85%A8%E5%B1%80%E5%9C%BA%E6%99%AFredux-%E5%9C%BA%E6%99%AF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那个例子,有个问题是没有这一段儿:

// App.tsx
// 将 Toast 组件包裹在 antd 的 App 组件中,以获取上下文
import { App as AntdApp, ConfigProvider, Layout } from 'antd';

import Toast from './toast';

function App() {
  return (
    <ConfigProvider>
      <AntdApp>
        <Toast />
      </AntdApp>
    </ConfigProvider>
  );
}

export default App;

导致我作为用户,不知道应该在什么时机导入它?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我写这个全局纯TS里面使用,我觉得这一段儿是比较奇怪的:

<AntdApp>
    <Toast />
</AntdApp>

在一个TS文件中使用,需要在我的App.tsx中加这么一段儿,这个文档中没有提到,感觉会挺迷惑的。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调整例子就够了?我理解 redux 一样是可以做数据获取的,不能来个库就写一个

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@shezhangzhang
Copy link
Contributor Author

shezhangzhang commented Mar 29, 2024

我看了一下这个文章:https://ant.design/docs/blog/why-not-static-cn
现在确实挺麻烦的,等于说我的需求只是在全局拦截器中报告fetch的错误,现在我按照文档的做法,需要去创建一个toast.ts里面使用App.useApp(), 导出message,然后去App.tsx中一顿操作。才可以正常使用 message.error()
但是其实我这个需求里面,没有那么想要这个context,我确实只需要一个静态的方法,简单易用就好。

image

Copy link

codecov bot commented Mar 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (9ccb419) to head (73246d9).

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #48167   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          736       736           
  Lines        12690     12690           
  Branches      3329      3329           
=========================================
  Hits         12690     12690           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants