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
Call this function from anywhere to create a toast.
65
66
66
67
#### Available Options
68
+
67
69
You can provide `ToastOptions` as the second argument. They will overwrite all options received from the `<Toaster/>` component.
68
70
69
71
```js
70
-
71
72
toast('This is a simple toast!', {
72
73
duration:5000,
73
74
position:'top-right',
@@ -92,38 +93,49 @@ toast('This is a simple toast!', {
92
93
role:'status',
93
94
'aria-live':'polite',
94
95
},
95
-
})
96
+
});
96
97
```
97
98
98
99
#### Creating Toasts
100
+
99
101
There are several options for creating toasts
100
102
101
103
##### Blank
104
+
102
105
```js
103
-
toast('This is a blank toast!')
106
+
toast('This is a blank toast!');
104
107
```
108
+
105
109
Blank toasts do not come with a default icon. However, you can set a custom JSX Element/Text (Emoji) icon by placing it in the `icon` option.
106
110
107
111
##### Success
112
+
108
113
```js
109
114
toast.success('Successfully saved!');
110
115
```
116
+
111
117
Creates a notification with an animated checkmark. Color accents can be themed with the `iconTheme` option.
112
118
113
119
##### Error
120
+
114
121
```js
115
122
toast.error('Something went wrong!');
116
123
```
124
+
117
125
Creates a notification with an animated error icon. Color accents can be themed with the `iconTheme` option.
118
126
119
127
##### Loading
128
+
120
129
```js
121
130
toast.loading('Loading Photos...');
122
131
```
132
+
123
133
Shows a toast with a loading indicator icon. The content can later be updated with an error or success icon. See how to update the toast content [here](#updating-toasts).
124
134
125
135
##### Promise
136
+
126
137
The `promise()` function can be used to create a toast from a promise. This function will automatically show a loading icon and update the toast with the result of the promise.
138
+
127
139
```jsx
128
140
constmyPromise=fetchData();
129
141
@@ -135,6 +147,7 @@ toast.promise(myPromise, {
135
147
```
136
148
137
149
##### Custom Toast
150
+
138
151
You also have the ability to completely customize the appearance of your toast.
139
152
A custom JSX Element can be passed in like so:
140
153
@@ -148,55 +161,61 @@ toast.custom(() => (
148
161
```
149
162
150
163
###### Advanced Option
164
+
151
165
You can also hook into the toast life-cycle by adding a parameter to the JSX Function call like so:
152
166
153
167
```jsx
154
-
toast.custom((t) => {
155
-
<div>
156
-
<h1>Custom Toast</h1>
157
-
<p>This is a custom toast!</p>
158
-
<p>{t.visible?'Showing':'I will close in 1 second'}</p>
159
-
<button
160
-
onClick={() =>toast.dismiss(t.id)}
161
-
>
162
-
Close Toast
163
-
</button>
164
-
</div>
165
-
}, {
166
-
unmoutDelay:1000,
167
-
})
168
+
toast.custom(
169
+
(t) => {
170
+
<div>
171
+
<h1>Custom Toast</h1>
172
+
<p>This is a custom toast!</p>
173
+
<p>{t.visible?'Showing':'I will close in 1 second'}</p>
You can manually dismiss a notification with `toast.dismiss`. Beware that it triggers the exit animation and does not remove the Toast instantly. Toasts will auto-remove after 500ms by default. You can adjust the dismiss duration with the `unmountDelay` option.
175
188
176
189
###### Dismiss Single Toast
190
+
177
191
```js
178
192
consttoastId=toast.loading('Loading...');
179
193
// ...
180
194
toast.dismiss(toastId);
181
195
```
196
+
182
197
Dismiss all toasts by omitting all arguments.
183
198
184
199
###### Dismiss All Toasts
200
+
185
201
```js
186
202
toast.dismiss();
187
203
```
188
204
189
205
##### Remove Toasts Instantly
206
+
190
207
Toasts can be removed instantly with toast.remove. This will not trigger the exit animation and remove the toast instantly.
208
+
191
209
```js
192
210
toast.remove(toastId);
193
211
// or
194
212
toast.remove();
195
213
```
196
214
197
-
198
215
##### Updating Toasts
216
+
199
217
Each toast call returns a unique id. Use this `id` in the toast options to update an existing toast.
0 commit comments