英文:
showNotification is not there anymore
问题
I am using the latest version "@mantine/notifications": "^5.10.4", but the example for notifications isn't working because showNotification doesn't exist. Do you know what may be the problem?
我正在使用最新版本的 "@mantine/notifications": "^5.10.4",但通知的示例不起作用,因为不存在 showNotification。您知道可能出了什么问题吗?
英文:
I am using the latest version "@mantine/notifications": "^5.10.4", but the example for notifications isn't working because showNotification doesn't exist. Do you know what may be the problem?
import React from 'react';
import { Group, Button } from '@mantine/core';
import { useNotifications } from '@mantine/notifications';
function Demo() {
const notifications = useNotifications();
return (
<Group position="center">
<Button
variant="outline"
onClick={() =>
notifications.showNotification({
title: 'Default notification',
message: 'Hey there, your code is awesome! 🤥',
})
}
>
Show notification
</Button>
</Group>
);
}
答案1
得分: 1
首先查看版本 @mantine/core 和 @mantine/notifications 是否相同。
您是否在根文件上调用了 <Notification /> 标签(如下所示
import { MantineProvider } from '@mantine/core';
import { Notifications } from '@mantine/notifications';
function Demo() {
return (
<MantineProvider withNormalizeCSS withGlobalStyles>
<Notifications />
<App />
</MantineProvider>
);
}
有关更多信息,您可以查看此文档。
英文:
First look at versions @mantine/core and @mantine/notifications are the same.
Did you call <Notification /> tag on your root file ( like this
import { MantineProvider } from '@mantine/core';
import { Notifications } from '@mantine/notifications';
function Demo() {
return (
<MantineProvider withNormalizeCSS withGlobalStyles>
<Notifications />
<App />
</MantineProvider>
);
}
for more information you can look this doc.
答案2
得分: 0
你不应该使用 useNotifications hook 来发送你的消息,而是从 @mantine/notifications 包中导入 shownotification 函数,并直接在你的代码中使用它。你的代码应该像这样重写:
import React from 'react';
import { Group, Button } from '@mantine/core';
import { showNotification } from '@mantine/notifications';
function Demo() {
return (
<Group position="center">
<Button
variant="outline"
onClick={() =>
showNotification({
title: 'Default notification',
message: 'Hey there, your code is awesome! 🎵',
})
}
>
Show notification
</Button>
</Group>
);
}
英文:
You should not be using the useNotifications hook to send your message, but rather import the shownotification function from the @mantine/notifications package and use it directly in your code. Your code should be rewritten like this:
import React from 'react';
import { Group, Button } from '@mantine/core';
import { showNotification } from '@mantine/notifications';
function Demo() {
return (
<Group position="center">
<Button
variant="outline"
onClick={() =>
showNotification({
title: 'Default notification',
message: 'Hey there, your code is awesome! 🤥',
})
}
>
Show notification
</Button>
</Group>
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论