use-execution-queue
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

use-execution-queue

Custom hook that implements a queue to execute functions

NPM JavaScript Style Guide

Install

npm install use-execution-queue
yarn add use-execution-queue

Usage

import * as React from "react";

import { useExecutionQueue } from "use-execution-queue";

const Example = () => {
  const [text, setText] = React.useState("Test");
  const [asyncItems, setAsyncItems] = React.useState([]);
  const { addToQueue } = useExecutionQueue();

  return (
    <div>
      <ul>
        {asyncItems.map((item, index) => (
          <li key={index}>{item}</li>
        ))}
      </ul>
      <input value={text} onChange={(e) => setText(e.target.value)} />
      <button
        onClick={() => {
          addToQueue(() => {
            setAsyncItems((previousItems) => [...previousItems, text]);
          });
        }}
      >
        Add Using Queue
      </button>
    </div>
  );
};

License

MIT © lucasfloriani


This hook is created using create-react-hook.

Readme

Keywords

none

Package Sidebar

Install

npm i use-execution-queue

Weekly Downloads

6

Version

0.0.1

License

MIT

Unpacked Size

673 kB

Total Files

27

Last publish

Collaborators

  • lucasfloriani