chore: Update message hooks demo (#38707)

* chore: update message hooks demo

* chore: update message hooks demo
This commit is contained in:
hms181231 2022-11-18 23:36:29 +08:00 committed by GitHub
parent 7cfe13f58b
commit 52d2b41f9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,28 +1,20 @@
import React, { useMemo } from 'react';
import React from 'react';
import { Button, message } from 'antd';
const Context = React.createContext({ name: 'Default' });
const App: React.FC = () => {
const [messageApi, contextHolder] = message.useMessage();
const info = () => {
messageApi.open({
type: 'info',
content: <Context.Consumer>{({ name }) => `Hello, ${name}!`}</Context.Consumer>,
duration: 1,
});
messageApi.info('Hello, Ant Design!');
};
const contextValue = useMemo(() => ({ name: 'Ant Design' }), []);
return (
<Context.Provider value={contextValue}>
<>
{contextHolder}
<Button type="primary" onClick={info}>
Display normal message
</Button>
</Context.Provider>
</>
);
};