0.0.1 • Published 6 years ago

react-show-data v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Light Toast

npm version Build Status

A light-weight React toast component with extremely easy API and 0 dependency. Online Demo

Installation

yarn add light-toast --save

Version 0.2.0 and above require React hooks support, please use with caution.

Usage

import Toast from 'light-toast';

const Button = () => (
  <button
    onClick={() => {
      Toast.info('message...', 3000, () => {
        // do something after the toast disappears
      });
    }}
  >
    click me
  </button>
);

API

Toast.info(content, duration, onClose);
Toast.success(content, duration, onClose);
Toast.fail(content, duration, onClose);
Toast.loading(content, onClose);
Toast.hide();
paramdetailtypedefault
contenttoast messagestring
durationmilliseconds delay to closenumber3000
onClosecallback function after closing the toastfunction

Notice

If you use Toast.loading(), you should call Toast.hide() by yourself to close the toast,
since this often happens when you make an asynchronous request.

When you are in loading state, you can call Toast.info(), Toast.success(), Toast.fail() directly to hide the loading message. This is useful when you want to hint something after waiting.