ant-design/components/message/demo/other.md
dingkang 34299b39ea
docs(message): use message hooks api (#35691)
* docs(message): use message hooks api

* docs(message): 保留一个静态方法调用

* docs: move docs demo order
2022-05-26 09:53:08 +08:00

1001 B

order title
1
zh-CN en-US
其他提示类型 Other types of message

zh-CN

包括成功、失败、警告。

en-US

Messages of success, error and warning types.

import { Button, message, Space } from 'antd';
import React from 'react';

const App: React.FC = () => {
  const [messageApi, contextHolder] = message.useMessage();

  const success = () => {
    messageApi.open({
      type: 'success',
      content: 'This is a success message',
    });
  };

  const error = () => {
    messageApi.open({
      type: 'error',
      content: 'This is an error message',
    });
  };

  const warning = () => {
    messageApi.open({
      type: 'warning',
      content: 'This is a warning message',
    });
  };

  return (
    <>
      {contextHolder}
      <Space>
        <Button onClick={success}>Success</Button>
        <Button onClick={error}>Error</Button>
        <Button onClick={warning}>Warning</Button>
      </Space>
    </>
  );
};

export default App;