Skip to content

Commit

Permalink
chore: Update message hooks demo (#38707)
Browse files Browse the repository at this point in the history
* chore: update message hooks demo

* chore: update message hooks demo
  • Loading branch information
hms181231 committed Nov 18, 2022
1 parent 7cfe13f commit 52d2b41
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions components/message/demo/hooks.tsx
@@ -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>
</>
);
};

Expand Down

0 comments on commit 52d2b41

Please sign in to comment.