0.2.6 • Published 1 year ago

query-toast v0.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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 onClick={() => {
        qt(handleSuccess);
      }}>
        Show Success Toast
      </button>

      <button onClick={() => {
        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"
                })
      });
    }}
0.2.0

1 year ago

0.2.6

1 year ago

0.2.2

1 year ago

0.2.4

1 year ago

0.1.65

2 years ago

0.1.62

2 years ago

0.1.61

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.2

2 years ago