API Reference
Below there is a full list of options and props that notistack supports. Some configurations can only be passed as props to SnackbarProvider
, some can only be passed in the options parameter of enqueueSnackbar
, and finally some can be passed in either places. On this page, the last category is called mutual props.
In the case of a mutual prop, you should pass it to SnackbarProvider
if you want to globally apply the setting to all Snackbars. However, for one-off configurations, you should pass it as an option to enqueueSnackbar
. Have look into the following example:
// all snackbars will automatically disappear after 5 seconds
<SnackbarProvider
autoHideDuration={5000}
/>
// this specific snackbar will disappear after 3 seconds
enqueueSnackbar('I am an exception', {
autoHideDuration: 3000
})
children
Most of the time this is your App. every component from this point onward will be able to show snackbars.
Type: React.ReactNode | React.ReactNode[]classes
Override or extend the styles applied to the container component or Snackbars.
dense
Denser margins for snackbars. Recommended to be used on mobile devices.
Type: boolean
Default: falsedomRoot
Valid and exist HTML Node element, used to target `ReactDOM.createPortal`
Type: HTMLElementhideIconVariant
Hides iconVariant if set to `true`.
Type: boolean
Default: falseiconVariant
Little icon that is displayed at left corner of a snackbar.
Type: { default: React.ReactNode, error: React.ReactNode, info: React.ReactNode, success: React.ReactNode, warning: React.ReactNode }maxSnack
Maximum snackbars that can be stacked on top of one another.
Type: number
Default: 3- ...and 19 other mutual props
key
Unique identifier to reference a snackbar.
Type: string | number
Default: random unique stringpersist
Snackbar stays on the screen, unless it is dismissed (programmatically or through user interaction).
Type: boolean
Default: false- ...and 19 other mutual props
These props can be passed in SnackbarProvider
props, as well as options
parameter of enqueueSnackbar
.
action
Callback used for getting action(s). actions are mostly buttons displayed in Snackbar.
Type: React.ReactNode | funccontent
Replace the snackbar. Callback used for displaying entirely customized snackbar.
Type: React.ReactNode | funcpreventDuplicate
Ignores displaying multiple snackbars with the same `message`
Type: boolean
Default: falsevariant
Used to easily display different variant of snackbars. When passed to `SnackbarProvider` all snackbars inherit the `variant`, unless you override it in `enqueueSnackbar` options.
Type: default | error | success | warning | info
Default: defaultTransitionComponent
The component used for the transition. (e.g. Slide, Grow, Zoom, etc.)
Default: SlideTransitionProps
Properties applied to Transition component (e.g. Slide, Grow, Zoom, etc.)
anchorOrigin
The anchor of the `Snackbar`.
Type: { horizontal: left | center | right, vertical: top | bottom }
Default: { horizontal: left, vertical: bottom }ariaAttributes
Aria attributes applied to snackbar's content component
Type: React.AriaAttributesautoHideDuration
The number of milliseconds to wait before automatically calling the `onClose` function. By default snackbars get closed after 5000 milliseconds. Set autoHideDuration to 'null' if you don't want snackbars to automatically close. Alternatively pass `persist: true` in the options parameter of enqueueSnackbar.
Type: number | null
Default: 5000disableWindowBlurListener
If `true`, the `autoHideDuration` timer will expire even if the window is not focused.
Type: boolean
Default: falseresumeHideDuration
The number of milliseconds to wait before dismissing after user interaction. If `autoHideDuration` property isn't specified, it does nothing. If `autoHideDuration` property is specified but `resumeHideDuration` isn't, we use the default value.
Type: number
Default: autoHideDuration / 2 ms.transitionDuration
The duration for the transition, in milliseconds. You may specify the duration with an object in the following shape: ```js transitionDuration={{ enter: 300, exit: 500 }} ```
Type: { appear: number, enter: number, exit: number }
Default: { enter: 225, exit: 195 }onClose
Callback fired before snackbar requests to get closed. The `reason` parameter can optionally be used to control the response to `onClose`.
Type: funconEnter
Callback fired before the transition is entering.
Type: funconEntered
Callback fired when the transition has entered.
Type: funconEntering
Callback fired when the transition is entering.
Type: funconExit
Callback fired before the transition is exiting.
Type: funconExited
Callback fired when the transition has exited.
Type: funconExiting
Callback fired when the transition is exiting.
Type: func
You can override styles of the components using classes
prop. Here are the valid keys.
Name | Description |
---|---|
root | Styles applied to Snackbar 's root element. |
anchorOriginTopCenter | Styles applied to Snackbar when anchorOrigin={{ vertical: top, horizontal: center }} |
anchorOriginBottomCenter | Styles applied to Snackbar when anchorOrigin={{ vertical: bottom, horizontal: center }} |
anchorOriginTopRight | Styles applied to Snackbar when anchorOrigin={{ vertical: top, horizontal: right }} |
anchorOriginBottomRight | Styles applied to Snackbar when anchorOrigin={{ vertical: bottom, horizontal: right }} |
anchorOriginTopLeft | Styles applied to Snackbar when anchorOrigin={{ vertical: top, horizontal: left }} |
anchorOriginBottomLeft | Styles applied to Snackbar when anchorOrigin={{ vertical: bottom, horizontal: left }} |
variantSuccess | Styles applied to Snackbar when { variant: success } |
variantError | Styles applied to Snackbar when { variant: error } |
variantWarning | Styles applied to Snackbar when { variant: warning } |
variantInfo | Styles applied to Snackbar when { variant: info } |
containerRoot | Styles applied to SnackbarContainer 's root element. |
containerAnchorOriginTopCenter | Styles applied to SnackbarContainer when anchorOrigin={{ vertical: top, horizontal: center }} |
containerAnchorOriginBottomCenter | Styles applied to SnackbarContainer when anchorOrigin={{ vertical: bottom, horizontal: center }} |
containerAnchorOriginTopRight | Styles applied to SnackbarContainer when anchorOrigin={{ vertical: top, horizontal: right }} |
containerAnchorOriginBottomRight | Styles applied to SnackbarContainer when anchorOrigin={{ vertical: bottom, horizontal: right }} |
containerAnchorOriginTopLeft | Styles applied to SnackbarContainer when anchorOrigin={{ vertical: top, horizontal: left }} |
containerAnchorOriginBottomLeft | Styles applied to SnackbarContainer when anchorOrigin={{ vertical: bottom, horizontal: left }} |