1.0.3 • Published 3 years ago

react-toast v1.0.3

Weekly downloads
76
License
MIT
Repository
github
Last release
3 years ago

Get started

Quick start

Install with yarn

yarn add react-toast

Install with NPM

npm install react-toast
import { ToastContainer, toast } from 'react-toast'

const App = () => {
  const wave = () => toast('Hi there 👋')

  return (
    <div>
      <button onClick={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
deplay (ms)numberdelay for toast6000

Toast

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

const success = () => 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:

const customToast = () =>
  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