useToast
@astryxdesign/core v0.7.1 · useToast
返回值
| 名称 | 类型 | 说明 |
|---|---|---|
show | (options: ToastOptions) => () => void | 弹出一条提示。返回的函数用来关掉这一条。hook 本身可以直接调用,所以 toast({ body }) 和 toast.show({ body }) 是一回事。 |
dismiss | (id: string) => void | 按 id 关掉一条提示。它挂在返回的函数上:toast.dismiss(id)。 |
clear | () => void | 关掉当前所有提示,写作 toast.clear()。 |
提示配置
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
body | string | — | 提示正文。必填。 |
type | 'info' | 'success' | 'warning' | 'error' | 'info' | 提示的类型,决定配色和图标。 |
isAutoHide | boolean | true | 是否自动消失。error 类型的提示默认留着,等人关掉。 |
autoHideDuration | number | 5000 | 自动消失前停留的毫秒数。 |
uniqueID | string | — | 同一个身份的多条提示会合并成一条。 |
collisionBehavior | 'ignore' | 'overwrite' | 'overwrite' | uniqueID 撞上时怎么处理。 |
endContent | Component | — | 正文后面的操作,例如「撤销」按钮。 |
onDismiss | (reason: 'auto' | 'manual') => void | — | 提示卡片自己关掉时调用:计时到了、点了关闭按钮、或者划走。 |
onHide | (reason: 'auto' | 'manual') => void | — | 提示被移除时调用,不管是哪种关闭方式。 |