Browse Source

chore: Update message hooks demo (#38707)

* chore: update message hooks demo

* chore: update message hooks demo
pull/38722/head
hms181231 2 years ago
committed by GitHub
parent
commit
52d2b41f9d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      components/message/demo/hooks.tsx

16
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>
</>
);
};

Loading…
Cancel
Save