mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
2cdf586291
* chore: fix lint * chore: fix lint * test: fix 16 * fix: lint
37 lines
817 B
TypeScript
37 lines
817 B
TypeScript
import React from 'react';
|
|
import { Button, Modal } from 'antd';
|
|
|
|
const App: React.FC = () => {
|
|
const [modal, contextHolder] = Modal.useModal();
|
|
|
|
const countDown = () => {
|
|
let secondsToGo = 5;
|
|
|
|
const instance = modal.success({
|
|
title: 'This is a notification message',
|
|
content: `This modal will be destroyed after ${secondsToGo} second.`,
|
|
});
|
|
|
|
const timer = setInterval(() => {
|
|
secondsToGo -= 1;
|
|
instance.update({
|
|
content: `This modal will be destroyed after ${secondsToGo} second.`,
|
|
});
|
|
}, 1000);
|
|
|
|
setTimeout(() => {
|
|
clearInterval(timer);
|
|
instance.destroy();
|
|
}, secondsToGo * 1000);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Button onClick={countDown}>Open modal to close in 5s</Button>
|
|
{contextHolder}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|