- Components Overview
- Changelogv6.1.4
- General
- Layout
- Navigation
- Data Entry
- Data Display
- Feedback
- Other
.ant-app element.message/notification/Modal from useApp without writing contextHolder manually.App provides upstream and downstream method calls through Context, because useApp needs to be used as a subcomponent, we recommend encapsulating App at the top level in the application.
importReactfrom'react';import{App}from'antd';constMyPage:React.FC=()=>{const{ message, notification, modal }=App.useApp();message.success('Good!');notification.info({ title:'Good'});modal.warning({ title:'Good'});// ....// other message, notification, modal static functionreturn<div>Hello word</div>;};constMyApp:React.FC=()=>(<App><MyPage/></App>);exportdefaultMyApp;
Note: App.useApp must be available under App.
The App component can only use the token in the ConfigProvider, if you need to use the Token, the ConfigProvider and the App component must appear in pairs.
<ConfigProvidertheme={{...}}><App>...</App></ConfigProvider>
<App><Space>...<App>...</App></Space></App>
// Entry componentimport{App}from'antd';importtype{MessageInstance}from'antd/es/message/interface';importtype{ModalStaticFunctions}from'antd/es/modal/confirm';importtype{NotificationInstance}from'antd/es/notification/interface';let message:MessageInstance;let notification:NotificationInstance;let modal:Omit<ModalStaticFunctions,'warn'>;exportdefault()=>{const staticFunction =App.useApp();message = staticFunction.message;modal = staticFunction.modal;notification = staticFunction.notification;returnnull;};export{ message, modal, notification };
// sub pageimportReactfrom'react';import{Button,Space}from'antd';import{ message }from'./store';exportdefault()=>{constshowMessage=()=>{message.success('Success!');};return(<Space><Buttontype="primary"onClick={showMessage}>Open message</Button></Space>);};
Common props ref:Common props
This component is available since
antd@5.1.0.
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| component | Config render element, if false will not create DOM node | ComponentType | false | div | 5.11.0 |
| message | Global config for Message | MessageConfig | - | 5.3.0 |
| notification | Global config for Notification | NotificationConfig | - | 5.3.0 |
<App component={false}>Make sure the App component is a valid html tag, so when you're turning on CSS variables, there's a container to hold the CSS class name. If not set, it defaults to the div tag. If set to false, no additional DOM nodes will be created, and no default styles will be provided.
Get instance for message, notification, modal.
Config for message, notification.