ant-design/components/notification/demo/with-icon.md
PCCCCCCC 1d09d6fe0c
Replace part of the Demo of the notification with the hooks (#35710)
* docs: modify the part demo to hooks

* docs: modify the part demo to hooks
2022-05-25 10:14:51 +08:00

48 lines
1.1 KiB
Markdown

---
order: 2
title:
zh-CN: 带有图标的通知提醒框
en-US: Notification with icon
---
## zh-CN
通知提醒框左侧有图标。
## en-US
A notification box with a icon at the left side.
```tsx
import { Button, notification, Space } from 'antd';
import React from 'react';
type NotificationType = 'success' | 'info' | 'warning' | 'error';
const App: React.FC = () => {
const [api, contextHolder] = notification.useNotification();
const openNotificationWithIcon = (type: NotificationType) => {
api[type]({
message: 'Notification Title',
description:
'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
});
};
return (
<>
{contextHolder}
<Space>
<Button onClick={() => openNotificationWithIcon('success')}>Success</Button>
<Button onClick={() => openNotificationWithIcon('info')}>Info</Button>
<Button onClick={() => openNotificationWithIcon('warning')}>Warning</Button>
<Button onClick={() => openNotificationWithIcon('error')}>Error</Button>
</Space>
</>
);
};
export default App;
```