项目作者: moharnadreza

项目描述 :
Minimal toast notifications for React.
高级语言: TypeScript
项目地址: git://github.com/moharnadreza/react-toast.git
创建时间: 2020-12-06T10:56:08Z
项目社区:https://github.com/moharnadreza/react-toast

开源协议:MIT License

下载



React Toast

React Toast



Minimal toast notifications for React.











Get started

Quick start

Install with yarn

  1. yarn add react-toast

Install with NPM

  1. npm install react-toast
  1. import { ToastContainer, toast } from 'react-toast'
  2. const App = () => {
  3. const wave = () => toast('Hi there 👋')
  4. return (
  5. <div>
  6. <button onClick={wave}>Say hi!</button>
  7. <ToastContainer ></ToastContainer>
  8. </div>
  9. )
  10. }

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:

Props Type Description Default
position top-left \ top-center \ top-right \ bottom-left \ bottom-center \ bottom-right position of toast bottom-left
delay (ms) number delay for toast 6000

Toast

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

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

or

  1. fetch('someRandomUrl')
  2. .then(res => res.json())
  3. .then(res => console.log(res))
  4. .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:

  1. const customToast = () =>
  2. toast('Morning! Have a good day.', {
  3. backgroundColor: '#8329C5',
  4. color: '#ffffff',
  5. })
Property Type Description Default
backgroundColor string background color of toast based on toast type, e.g. success will be green
color string color of text in toast #ffffff

License

MIT