You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用@mantine/notifications v5.10.4时showNotification不存在问题求助

问题原因及解决方案
  • 版本方法名差异:你使用的是Mantine v5版本(^5.10.4),该版本中useNotifications返回的方法名为show,而showNotification是Mantine v6才新增的方法名,这是导致方法不存在的直接原因。

  • 修复方案:

    1. 将代码里的notifications.showNotification替换为notifications.show
    2. 确认应用根组件已包裹NotificationsProvider——这是使用通知组件的必要前提,缺少它useNotifications无法正常初始化

修改后的代码示例:

import React from 'react';
import { Group, Button } from '@mantine/core';
import { useNotifications, NotificationsProvider } from '@mantine/notifications';

function Demo() {
  const notifications = useNotifications();

  return (
    <Group position="center">
      <Button
        variant="outline"
        onClick={() =>
          notifications.show({
            title: 'Default notification',
            message: 'Hey there, your code is awesome! 🤥',
          })
        }
      >
        Show notification
      </Button>
    </Group>
  );
}

// 根组件必须包裹NotificationsProvider
function App() {
  return (
    <NotificationsProvider>
      <Demo />
    </NotificationsProvider>
  );
}

内容的提问来源于stack exchange,提问作者whowhenhow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 22:45:29