Socket
Socket
Sign inDemoInstall

react-toast

Package Overview
Dependencies
3
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-toast

A minimal toast notification package for React.


Version published
Maintainers
1
Created

Readme

Source

React Toast

React Toast

A minimal toast notification package for React.

Get started

Quick start

yarn add 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

Here's a little demo.

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

Of course you can display custom toasts 😅, here's a gist 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

Keywords

FAQs

Last updated on 19 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc