1// toast in react
2// create toast.js component
3
4import { toast } from 'react-toastify';
5import 'react-toastify/dist/ReactToastify.css';
6
7toast.configure()
8
9const options = {
10 autoClose: 2000,
11 className: '',
12 position: toast.POSITION.TOP_RIGHT,
13};
14
15export const toastSuccess = message => {
16 console.log("Hello0 success toast")
17 toast.success(message, options);
18}
19
20export const toastError = message => {
21 toast.error(message, options);
22}
23
24export const toastWarning = message => {
25 toast.warn(message, options);
26}
27
28export const toastInformation = message => {
29 toast.info(message, options);
30}
31
32export const toastDark = message => {
33 toast.dark(message, options);
34}
35
36export const toastDefault = message => {
37 toast(message, options);
38}
39
40// wherever in need that toast use like this
41
42import { toastError, toastSuccess } from "./Toast";
43toastSuccess("User successfully registered");
44toastError("User is not created try again");
45
1import { ToastProvider } from 'react-toast-notifications';
2import { Snack } from '../snackbar';
3
4const App = () => (
5 <ToastProvider
6 autoDismiss
7 autoDismissTimeout={6000}
8 components={{ Toast: Snack }}
9 placement="bottom-center"
10 appearance: 'success',
11 autoDismiss: true,
12 >
13 ...
14 </ToastProvider>
15);
16
1/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
2
3import React, { useState } from 'react';
4import { Button, Toast, ToastBody, ToastHeader } from 'reactstrap';
5
6const ToastDismissExample = (props) => {
7 const { buttonLabel } = props;
8 const [show, setShow] = useState(false);
9
10 const toggle = () => setShow(!show);
11
12 return (
13 <div>
14 <Button color="primary" onClick={toggle}>{buttonLabel}</Button>
15 <br />
16 <br />
17 <Toast isOpen={show}>
18 <ToastHeader toggle={toggle}>Toast title</ToastHeader>
19 <ToastBody>
20 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
21 </ToastBody>
22 </Toast>
23 </div>
24 );
25}
26
27export default ToastDismissExample;
28
1npm install react-native-simple-toast --save
2react-native link react-native-simple-toast // only RN < 0.60
3cd ios && pod install
1import React from 'react';
2import { Toast, ToastBody, ToastHeader } from 'reactstrap';
3
4const Example = (props) => {
5 return (
6 <div>
7 <div className="p-3 my-2 rounded">
8 <Toast>
9 <ToastHeader>
10 Reactstrap
11 </ToastHeader>
12 <ToastBody>
13 This is a toast on a white background — check it out!
14 </ToastBody>
15 </Toast>
16 </div>
17 <div className="p-3 my-2 rounded bg-docs-transparent-grid">
18 <Toast>
19 <ToastHeader>
20 Reactstrap
21 </ToastHeader>
22 <ToastBody>
23 This is a toast on a gridded background — check it out!
24 </ToastBody>
25 </Toast>
26 </div>
27 <div className="p-3 bg-primary my-2 rounded">
28 <Toast>
29 <ToastHeader>
30 Reactstrap
31 </ToastHeader>
32 <ToastBody>
33 This is a toast on a primary background — check it out!
34 </ToastBody>
35 </Toast>
36 </div>
37 <div className="p-3 bg-secondary my-2 rounded">
38 <Toast>
39 <ToastHeader>
40 Reactstrap
41 </ToastHeader>
42 <ToastBody>
43 This is a toast on a secondary background — check it out!
44 </ToastBody>
45 </Toast>
46 </div>
47 <div className="p-3 bg-success my-2 rounded">
48 <Toast>
49 <ToastHeader>
50 Reactstrap
51 </ToastHeader>
52 <ToastBody>
53 This is a toast on a success background — check it out!
54 </ToastBody>
55 </Toast>
56 </div>
57 <div className="p-3 bg-danger my-2 rounded">
58 <Toast>
59 <ToastHeader>
60 Reactstrap
61 </ToastHeader>
62 <ToastBody>
63 This is a toast on a danger background — check it out!
64 </ToastBody>
65 </Toast>
66 </div>
67 <div className="p-3 bg-warning my-2 rounded">
68 <Toast>
69 <ToastHeader>
70 Reactstrap
71 </ToastHeader>
72 <ToastBody>
73 This is a toast on a warning background — check it out!
74 </ToastBody>
75 </Toast>
76 </div>
77 <div className="p-3 bg-info my-2 rounded">
78 <Toast>
79 <ToastHeader>
80 Reactstrap
81 </ToastHeader>
82 <ToastBody>
83 This is a toast on an info background — check it out!
84 </ToastBody>
85 </Toast>
86 </div>
87 <div className="p-3 bg-dark my-2 rounded">
88 <Toast>
89 <ToastHeader>
90 Reactstrap
91 </ToastHeader>
92 <ToastBody>
93 This is a toast on a dark background — check it out!
94 </ToastBody>
95 </Toast>
96 </div>
97 <div className="p-3 my-2 rounded" style={{ background: 'black' }}>
98 <Toast>
99 <ToastHeader>
100 Reactstrap
101 </ToastHeader>
102 <ToastBody>
103 This is a toast on a black background — check it out!
104 </ToastBody>
105 </Toast>
106 </div>
107 </div>
108 );
109};
110
111export default Example;
112