--- title: Snacks description: "`Snacks` is a component for controlling notifications used in forms and other similar situations." links: - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/snacks - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-snacks--basic --- ```tsx const { snack, snacks } = useSnacks() return ( ) ``` ## Usage ```tsx import { useSnacks, Snacks } from "@yamada-ui/react" ``` ```tsx import { useSnacks, Snacks } from "@/components/ui" ``` ```tsx import { useSnacks, Snacks } from "@workspaces/ui" ``` ```tsx ``` ### Change Variant ```tsx const { snack, snacks } = useSnacks() return ( {(variant) => ( )} ) ``` ### Change Color Scheme ```tsx const { snack, snacks } = useSnacks() return ( {(colorScheme) => ( )} ) ``` ### Change Status To change status, set the `status` prop. ```tsx const { snack, snacks } = useSnacks() return ( {(status) => ( )} ) ``` ### Change Loading Scheme To change loading scheme, set the `loadingScheme` prop. ```tsx const { snack, snacks } = useSnacks() return ( {(loadingScheme) => ( )} ) ``` ### Change Direction To change direction, set `"start"` or `"end"` to the `direction` prop. The default is `"start"`. ```tsx const { snack, snacks } = useSnacks({ direction: "end" }) return ( ) ``` ### Limit the Number of Displays To limit the number of displays, set a number to the `limit` prop. If you want to display an unlimited number of notifications, set it to `null`. By default, `3` is set. ```tsx const { snack, snacks } = useSnacks({ limit: 5 }) return ( ) ``` ### Set the Display Duration To set the display duration, set a number (in milliseconds) to the `duration` prop. ```tsx const { snack, snacks } = useSnacks() return ( ) ``` ### Disable the Close Button To disable the close button, set `closable` to `false`. ```tsx const { snack, snacks } = useSnacks({ closable: false }) return ( ) ``` ### Close Notifications To close notifications, use `snack.close` or `snack.closeAll`. ```tsx const { snack, snacks } = useSnacks() const id = useRef(undefined) return ( ) ``` ### Update Notifications To update notifications, use `snack.update`. ```tsx const { snack, snacks } = useSnacks() const id = useRef(undefined) return ( ) ``` ## Props | Prop | Default | Type | Description | | ----------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | | `as` | - | `DOMElement` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `snacks` | - | `UseSnacksReturn["snacks"]` | The snacks created by `useSnacks`. | | `gap` | `"md"` | `"-0.5" \| "-1.5" \| "-1" \| "-10" \| "-11" \| "-12" \| "-13" \| "-14" \| "-15" \| "-16" ...` | The CSS `gap` property. | | `gutter` | `[0, "lg"]` | `[CSSProps["paddingTop"], CSSProps["paddingBottom"]]` | A property that provides spacing between the top and bottom. | | `listProps` | - | `HTMLMotionProps` | Props for the snacks list element. | | `negativeMargins` | `true` | `boolean` | If `true`, apply gutter value to negative margins |