You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportdefault ({ children }) => <Layoutmeta={meta}>{children}</Layout>;
9
+
10
+
# Multiple Toasters
11
+
12
+
React Hot Toast supports multiple toaster instances in your app, They can be used and configured independently of each other. This is useful for having notifications in different areas of your app.
13
+
14
+
You can use multiple toasters by creating a [`Toaster`](/docs/toaster) with a unique `toasterId`:
15
+
16
+
```jsx
17
+
<Toaster toasterId="sidebar"/>
18
+
```
19
+
20
+
## Example
21
+
22
+
This example shows two toasters, each maintaining their own state and configuration.
The `useToaster()` hook provides you a **headless system that will manage the notification state** for you. This makes building your own notification system much easier.
12
+
The `useToaster()` hook provides a **headless toast management system** for building custom notification UIs. It manages toast state and lifecycle without rendering any components.
13
13
14
-
It solves the following problems for you:
14
+
It handles pausing on hover, auto-removal, and provides a 1-second removal delay with `visible` flag for smooth animations.
15
15
16
-
- Built-in dispatch system with [`toast()`](/docs/toast)
17
-
- Handlers to pause toasts on hover
18
-
- Automatically remove expired toasts
19
-
- Support for unmount animations. Removal is delayed by 1s, but sets `visible` on the toast to `false`.
16
+
**Alternative**: Use [`useToasterStore()`](/docs/use-toaster-store) if you already have a toaster instance and only need the state.
20
17
21
-
### Importing from headless
18
+
### Importing
22
19
23
-
You can import only the core of the library with `react-hot-toast/headless`. It won't include any styles, dependencies or custom components.
20
+
```jsx
21
+
import { useToaster } from'react-hot-toast';
22
+
```
23
+
24
+
You can also import from the headless entry point to exclude UI components:
Be aware: [react-hot-toast 2.0](/docs/version-2)adds support for **custom render functions**, an easier method to render custom notification components.
30
+
**Note**: [React Hot Toast 2.0](/docs/version-2)includes **custom render functions** for easier custom components.
30
31
31
-
It's recommended to only have one `<Toaster/>` or `useToaster()` in your app at a time. If you need the current state without the handlers, you should use [`useToasterStore()`](/docs/use-toaster-store) instead.
Array of all toasts in this toaster instance, including hidden ones for animation purposes.
65
+
66
+
#### `handlers`
34
67
35
-
Headless mode is perfectly suited to add notifications to your React Native app. You can check out [this example](<https://snack.expo.io/@timo/react-hot-toast---usetoaster()---react-native>).
68
+
-**`startPause()`**: Pause all toast timers (useful for hover states)
69
+
-**`endPause()`**: Resume all toast timers
70
+
-**`updateHeight(toastId, height)`**: Update toast height for offset calculations
71
+
-**`calculateOffset(toast, options)`**: Calculate vertical offset for toast positioning
72
+
73
+
## Multiple Toasters
74
+
75
+
You can create multiple independent toaster instances by providing a unique `toasterId`. See the [Multiple Toasters](/docs/multi-toaster) guide for detailed examples.
Instead of mapping over `visibleToasts` we'll use `toasts`, which includes all hidden toasts. We animate them based on`toast.visible`. Toasts will be removed from 1 second after being dismissed, which give us enough time to animate.
112
+
This example uses all `toasts` (including hidden ones) to enable smooth animations. The`toast.visible` property controls opacity, while the 1-second removal delay provides time for exit animations.
68
113
69
-
You can play with the demo on [CodeSandbox](https://codesandbox.io/s/react-hot-toast-usetoaster-headless-example-zw7op?file=/src/App.js).
The headless API works perfectly with React Native. View the [React Native example](<https://snack.expo.io/@timo/react-hot-toast---usetoaster()---react-native>) for implementation details.
0 commit comments