MUI替代ANTD通知

发布于 2025-01-18 05:53:03 字数 450 浏览 2 评论 0原文

我已经使用 antD 的 notification api 一段时间了。对于我的最新项目,我正在使用 MUI。我需要集中 API 请求的错误处理,并且我使用通用的 Axios 实例来处理该问题。 有 onSuccessonError 方法来处理这些场景。目前,我使用 console.log 来显示错误或成功消息。使用 antD,我有以下选择。

notification.success({
    message: data.title,
    description: message,
    duration: 5,
  });

通知可以从应用程序中的任何位置触发,不一定是从反应组件触发。 对于 MUI 我无法做到这一点。 MUI 可以做到这一点吗?我可以采用自定义方法在 MUI Snackbars 中显示错误/成功消息吗?

I have been using antD's notification api for some time. For my newest project, I am using MUI. I need to centralize the error handling for API requests, and I am using a common Axios instance to handle that.
There are onSuccess and onError methods to handle the scenarios. Currently, I am using console.log to display errors or success messages. With antD I had the following option.

notification.success({
    message: data.title,
    description: message,
    duration: 5,
  });

The notification could be triggered from anywhere in the application, not necessarily from a react component.
With MUI I am unable to do that. Is this possible with MUI? Can I work on a custom approach to display my error/ success messages in MUI Snackbars?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零度° 2025-01-25 05:53:03

经过一番研究,我发现MUI没有提供此类实施。我现在正在实施的是Redux的方法。 https://www.pluralsight.com/guides/guides/guides/guides/与反射和redux进行集中式交流
给出了一个很好的指南。

After a bit of research, I found out that there is no such implementation provided by MUI. What I am implementing now is an approach with Redux. https://www.pluralsight.com/guides/centralized-error-handing-with-react-and-redux
has given a good guide.

两仪 2025-01-25 05:53:03

您可以使用 notistack 。它遵循材料设计,非常易于使用。

You could use notistack. It follows material design and really easy to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文