mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 03:59:01 +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';
|
||||
|
||||
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>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user