For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/message.md.
Use the key returned by loading() to replace the loading message with a result. A matching key replaces the options rather than merging them, and restarts the timer with the new duration.
async.tsx
import { Button, useMessage } from '@ifhover/leaf-ui';import { useState } from 'react';export function MessageAsync() { const { message } = useMessage(); const [saving, setSaving] = useState(false); async function save() { setSaving(true); const key = message.loading('Saving'); await new Promise((resolve) => setTimeout(resolve, 1200)); message.open({ key, type: 'success', content: 'Changes saved' }); setSaving(false); } return ( <Button loading={saving} onClick={save}> Save asynchronously </Button> );}
The two buttons below belong to separate components. Components under the same provider share a queue and can update the same message with a shared key. Nested ConfigProvider regions share that queue while keeping the calling component's theme and language.
Messages remain after the calling component unmounts; ongoing work can still update them. Unmounting the entry provider removes its messages and timers.
Use MessageProvider instead of ConfigProvider for standalone message support, or add it explicitly to create an independent queue. Separate React applications and SSR requests have independent queues.
import { MessageProvider } from '@ifhover/leaf-ui';export function Root() { return <MessageProvider><App /></MessageProvider>;}
Property
Type
Default
Description
children
ReactNode
—
Contents sharing this independent message queue; ConfigProvider already supplies one, reused by nested ConfigProviders.