2016-03-31 09:40:55 +08:00
---
order: 1
2016-08-28 17:45:27 +08:00
title:
2016-08-17 11:07:02 +08:00
zh-CN: 自动关闭的延时
en-US: Duration after which the notification box is closed
2016-03-31 09:40:55 +08:00
---
2015-08-03 15:17:12 +08:00
2016-08-17 11:07:02 +08:00
## zh-CN
2020-11-08 15:04:02 +08:00
自定义通知框自动关闭的延时,默认 `4.5s` ,取消自动关闭只要将该值设为 `0` 即可。
2015-08-03 15:17:12 +08:00
2016-08-17 11:07:02 +08:00
## en-US
2019-05-07 14:57:32 +08:00
`Duration` can be used to specify how long the notification stays open. After the duration time elapses, the notification closes automatically. If not specified, default value is 4.5 seconds. If you set the value to 0, the notification box will never close automatically.
2016-08-17 11:07:02 +08:00
2022-05-19 09:46:26 +08:00
```tsx
2015-10-28 20:55:49 +08:00
import { Button, notification } from 'antd';
2022-05-21 22:14:15 +08:00
import React from 'react';
2015-08-03 15:17:12 +08:00
2022-05-25 10:14:51 +08:00
const App: React.FC = () => {
const [api, contextHolder] = notification.useNotification();
const openNotification = () => {
api.open({
message: 'Notification Title',
description:
'I will never close automatically. This is a purposely very very long description that has many many characters and words.',
duration: 0,
});
2015-08-03 15:17:12 +08:00
};
2022-05-25 10:14:51 +08:00
return (
< >
{contextHolder}
< Button type = "primary" onClick = {openNotification} >
Open the notification box
< / Button >
< />
);
};
2022-05-19 09:46:26 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```