mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
chore: Update message hooks demo (#38707)
* chore: update message hooks demo * chore: update message hooks demo
This commit is contained in:
parent
7cfe13f58b
commit
52d2b41f9d
@ -1,28 +1,20 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React from 'react';
|
||||||
import { Button, message } from 'antd';
|
import { Button, message } from 'antd';
|
||||||
|
|
||||||
const Context = React.createContext({ name: 'Default' });
|
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
const info = () => {
|
const info = () => {
|
||||||
messageApi.open({
|
messageApi.info('Hello, Ant Design!');
|
||||||
type: 'info',
|
|
||||||
content: <Context.Consumer>{({ name }) => `Hello, ${name}!`}</Context.Consumer>,
|
|
||||||
duration: 1,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const contextValue = useMemo(() => ({ name: 'Ant Design' }), []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Context.Provider value={contextValue}>
|
<>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
<Button type="primary" onClick={info}>
|
<Button type="primary" onClick={info}>
|
||||||
Display normal message
|
Display normal message
|
||||||
</Button>
|
</Button>
|
||||||
</Context.Provider>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user