showNotification 不再存在

huangapple go评论116阅读模式
英文:

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 &#39;react&#39;;
import { Group, Button } from &#39;@mantine/core&#39;;
import { showNotification } from &#39;@mantine/notifications&#39;;

function Demo() {
  return (
    &lt;Group position=&quot;center&quot;&gt;
      &lt;Button
        variant=&quot;outline&quot;
        onClick={() =&gt;
          showNotification({
            title: &#39;Default notification&#39;,
            message: &#39;Hey there, your code is awesome! &#129317;&#39;,
          })
        }
      &gt;
        Show notification
      &lt;/Button&gt;
    &lt;/Group&gt;
  );
}

huangapple
  • 本文由 发表于 2023年2月24日 02:12:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定