MUI替代ANTD通知
我已经使用 antD 的 notification
api 一段时间了。对于我的最新项目,我正在使用 MUI。我需要集中 API 请求的错误处理,并且我使用通用的 Axios 实例来处理该问题。 有 onSuccess
和 onError
方法来处理这些场景。目前,我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一番研究,我发现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.
您可以使用
notistack
。它遵循材料设计,非常易于使用。You could use
notistack
. It follows material design and really easy to use.