mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-10 05:58:39 +08:00
30 lines
707 B
TypeScript
30 lines
707 B
TypeScript
|
import React, { useMemo } 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,
|
||
|
});
|
||
|
};
|
||
|
|
||
|
const contextValue = useMemo(() => ({ name: 'Ant Design' }), []);
|
||
|
|
||
|
return (
|
||
|
<Context.Provider value={contextValue}>
|
||
|
{contextHolder}
|
||
|
<Button type="primary" onClick={info}>
|
||
|
Display normal message
|
||
|
</Button>
|
||
|
</Context.Provider>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default App;
|