xxxxxxxxxx
React Toast Plus
npm install react-toast-plus
Or with Yarn:
yarn add react-toast-plus
Basic Setup
Wrap your application with the ToastProvider to enable toast notifications:
import React from 'react';
import ReactDOM from 'react-dom';
import { ToastProvider } from 'react-toast-plus';
import App from './App';
ReactDOM.render(
<ToastProvider>
<App />
</ToastProvider>,
document.getElementById('root')
);
Adding Toasts
You can use the useToast hook to add toasts:
import React from 'react';
import { useToast } from 'react-toast-plus';
const App = () => {
const { addToast } = useToast();
const showToast = () => {
addToast('This is a toast!');
};
return <button onClick={showToast}>Show Toast</button>;
};
xxxxxxxxxx
<ToastProvider toastOptions={{
closeOnClick: true,
successOptions: {
style: { backgroundColor: 'green' },
icon: <cutomIcon/>
},
errorOptions: {
closeButton: { visible: false } ,
lifetime: 5000
},
}}>
<App />
</ToastProvider>
xxxxxxxxxx
// toast in react
// create toast.js component
import { toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
toast.configure()
const options = {
autoClose: 2000,
className: '',
position: toast.POSITION.TOP_RIGHT,
};
export const toastSuccess = message => {
console.log("Hello0 success toast")
toast.success(message, options);
}
export const toastError = message => {
toast.error(message, options);
}
export const toastWarning = message => {
toast.warn(message, options);
}
export const toastInformation = message => {
toast.info(message, options);
}
export const toastDark = message => {
toast.dark(message, options);
}
export const toastDefault = message => {
toast(message, options);
}
// wherever in need that toast use like this
import { toastError, toastSuccess } from "./Toast";
toastSuccess("User successfully registered");
toastError("User is not created try again");
xxxxxxxxxx
React Toast Plus is a lightweight, customizable toast notification library for React.
Installation
To install react-toast-plus, run:
npm install react-toast-plus
Or with Yarn:
yarn add react-toast-plus
Basic Setup
Wrap your application with the ToastProvider to enable toast notifications:
import React from 'react';
import ReactDOM from 'react-dom';
import { ToastProvider } from 'react-toast-plus';
import App from './App';
ReactDOM.render(
<ToastProvider>
<App />
</ToastProvider>,
document.getElementById('root')
);
Adding Toasts
import React from 'react';
import { useToast } from 'react-toast-plus';
const App = () => {
const { addToast } = useToast();
const showToast = () => {
addToast('This is a toast!');
};
return <button onClick={showToast}>Show Toast</button>;
};
xxxxxxxxxx
// npm install react-simple-toasts
toast('Hello, world!', 5000);
// ^ message ^ duration
xxxxxxxxxx
string stringtofind = "search-string";
reallylongstring.Contains(stringtofind);
xxxxxxxxxx
You can use the IndexOf method of the StringBuilder class to determine if the string stored in the stringtofind object is contained within the sb object. Here's an example of how you could do it:
if (sb.ToString().IndexOf(stringtofind) != -1)
{
// the string was found in the StringBuilder object
}
else
{
// the string was not found in the StringBuilder object
}
Note that the ToString() method is called on the StringBuilder object to convert it to a regular string before calling IndexOf.
xxxxxxxxxx
if (sb.ToString().Contains(stringtofind)) {
// stringtofind is found in sb
} else {
// stringtofind is not found in sb
}
xxxxxxxxxx
import React from 'react';
import { ToastContainer, toast } from 'material-react-toastify';
import 'material-react-toastify/dist/ReactToastify.css';
function App(){
const notify = () => toast("Wow so easy !");
return (
<div>
<button onClick={notify}>Notify !</button>
<ToastContainer />
</div>
);
}