JGuang

Message

Message · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

Message

Lightweight global feedback triggered by user actions.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Basic: The simplest usage.
  • Type: There are 5 different types of Message, info, success, warning, error, normal.
  • Update: By specifying the id, the existing Message can be updated.
  • Position: Message has 2 different positions.
  • Update duration: By specifying the id, the duration attribute of the existing Message can be updated.
  • Manual close: Message.xxx() will return a function, use this function to close the notification.
  • Closable: Set closable to show the close button.
  • Hooks - Usage: You can use useMessage to create a dialog that can read the context. But the message rendered by useMessage is mounted where the contextHolder is. The container cannot be modified via getContainer().
  • Custom animation effects: You can implement custom animations through transitionClassNames and transitionTimeout The animation implementation is based on react-transition-group

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

Message

PropertyDescriptionTypeDefaultValueVersion
closableWhether to show the close buttonbooleantrue-
showIconWhether to show the iconbooleantrue-
durationAutomatic shutdown time, the unit is msnumber3000-
idThe unique identifier of the current message, which can be used to update the messagestring--
transitionClassNamesClassNames of react-transition-group of the message pop-up animation, see classNamesstring--
positionThe position of the message'top' | 'bottom'--
closeIconCustom the close button on top-right of the drawer dialogReactNode-2.50.0
iconCustom iconReactNode--
classNameAdditional css classstring | string[]--
contentMessage contentReactNode | string (Required)--
styleAdditional styleCSSProperties--
transitionTimeouttimeout of react-transition-group of the message pop-up animation, see timeout{enter?: number;exit?: number;}{enter: 100, exit: 300}2.43.0
onCloseCallback when close() => void--

Methods

  • Message.info(content: String) / Message.info(config: Object)
  • Message.success(content: String) / Message.success(config: Object)
  • Message.warning(content: String) / Message.warning(config: Object)
  • Message.error(content: String) / Message.error(config: Object)
  • Message.normal(content: String) / Message.normal(config: Object)
  • Message.loading(content: String) / Message.loading(config: Object)
  • Message.clear()

Global config

Message.config(options)

PropertyDescriptionTypeDefault
maxCountMaximum number of notificationsnumber-
getContainerContainer of the notification() => HTMLElement() => document.body
durationThe time when the notification is automatically closednumber3000
prefixClsClassName prefixstringarco