Skip to content

useSnackbar API

API reference docs for the useSnackbar hook. Learn about the input parameters and other APIs of this exported module.

Demos

For examples and details on the usage of this React hook, visit the demo pages:

Import

import { useSnackbar } from '@mui/base/SnackbarUnstyled';


The basic building block for creating custom snackbar.

Parameters

NameTypeDefaultDescription
autoHideDurationnumber | nullnull
The number of milliseconds to wait before automatically calling the onClose function. onClose should then set the state of the open prop to hide the Snackbar. This behavior is disabled by default with the null value.
disableWindowBlurListenerbooleanfalse
If true, the autoHideDuration timer will expire even if the window is not focused.
onClose(event: React.SyntheticEvent<any> | Event | null, reason: SnackbarCloseReason) => void
Callback fired when the component requests to be closed. Typically onClose is used to set state in the parent component, which is used to control the Snackbar open prop. The reason parameter can optionally be used to control the response to onClose, for example ignoring clickaway.
openboolean
If true, the component is shown.
refReact.Ref<any>
resumeHideDurationnumber
The number of milliseconds to wait before dismissing after user interaction. If autoHideDuration prop isn't specified, it does nothing. If autoHideDuration prop is specified but resumeHideDuration isn't, we default to autoHideDuration / 2 ms.

Return value

NameTypeDefaultDescription