[go: up one dir, main page]

query-toast
TypeScript icon, indicating that this package has built-in type declarations

0.2.6 • Public • Published

Query Toast

Query Toast is a lightweight and customizable toast notification library for React applications.

Installation

You can install Query Toast via npm or yarn:

npm install query-toast
yarn add query-toast

Usage

Importing

import { qt, QTContainer } from 'query-toast';

Example Usage

import { qt, QTContainer } from 'query-toast';

function ExampleComponent() {
  const handleSuccess = async () => {
    // Simulate an asynchronous process with a delay of 1000ms
    await new Promise(resolve => setTimeout(resolve, 1000));
    return { message: "Success! Process completed." };
  };

  const handleError = async () => {
    // Simulate an asynchronous process with a delay of 1000ms
    await new Promise(resolve => setTimeout(resolve, 1000));
    return { type: "error", message: "An error occurred." };
  };

  return (
    <div>
      <QTContainer />

      <button  => {
        qt(handleSuccess);
      }}>
        Show Success Toast
      </button>

      <button  => {
        qt(handleError);
      }}>
        Show Error Toast
      </button>
    </div>
  );
}

export default ExampleComponent;

In this example, the handleSuccess and handleError functions simulate asynchronous processes using setTimeout to delay the resolution of a promise by 1000 milliseconds. Then, they return the corresponding message or error object. When the buttons are clicked, these functions are passed to qt, triggering the toast notifications after the specified delay.


    <QTContainer />
onClick={() => {
      qt(async() => {
        // handle your process...
        return({ message: "ok"});
      });
    }}
onClick={() => {
      qt(() => {
        // handle your process...

        return({ 
                type: "error"
                message: "...error / rejected"
                })
      });
    }}

Readme

Keywords

Package Sidebar

Install

npm i query-toast

Weekly Downloads

0

Version

0.2.6

License

MIT

Unpacked Size

23.2 kB

Total Files

18

Last publish

Collaborators

  • md-anamul-haque