Skip to content

Repository files navigation

React Toast

React Toast

Minimal toast notifications for React.

Get started

Quick start

Install with yarn

yarn add react-toast

Install with NPM

npm install react-toast
import{ToastContainer,toast}from'react-toast'constApp=()=>{constwave=()=>toast('Hi there 👋')return(<div><buttononClick={wave}>Say hi!</button><ToastContainer/></div>)}

Demo

Demo on CodeSandbox.

Docs

Toast Container

To use react-toast, you need to put ToastContainer in a top-level component in your application. e.g. App.js

It can take some props, here's a list of them:

PropsTypeDescriptionDefault
positiontop-left | top-center | top-right | bottom-left | bottom-center | bottom-rightposition of toastbottom-left
delay (ms)numberdelay for toast6000

Toast

There are 4 base toast type available, success, error, info and warn. For instance:

constsuccess=()=>toast.success('Message sent successfully!')

or

fetch('someRandomUrl').then(res=>res.json()).then(res=>console.log(res)).catch(err=>toast.error(err.message))

Custom toast

You can display custom styled toasts, here's an example and a list of options that are available for customization:

constcustomToast=()=>toast('Morning! Have a good day.',{backgroundColor: '#8329C5',color: '#ffffff',})
PropertyTypeDescriptionDefault
backgroundColorstringbackground color of toastbased on toast type, e.g. success will be green
colorstringcolor of text in toast#ffffff

License

MIT

About

Minimal toast notifications for React.

Topics

Resources

Contributing

Stars

84 stars

Watchers

3 watching

Forks

Releases

Used by

Contributors

Languages