npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-use-queue

v0.5.0

Published

A simple task queue implementation for React

Downloads

608

Readme

React useQueue

A simple job-based asynchronous queue for react and react-native

A very small and basic implementation of an asyncronous queue. It's an easy way to add jobs to a list and add a callback to be fired when all of the jobs are complete.

While it's not exactly crammed full of features, it's a convenient and lightweight way to do work on unused cycles.

Example Useage

First, add it to your project as you normally would.

$ npm i -s react-use-queue

import useQueue from "react-use-queue";

Next, simply use the hook as so.

const Queue = useQueue();

Now, you can add tasks:

  Queue.addJob({
    task: () => doSomething()),
  });

As of 0.5.0 you can also just add callbacks like so

  Queue.addJob(doSomething),

You can even add promises and do something with their result:

  Queue.addJob({
    task: () => doSomething().then(result => doSomethingElse(result)),
  });

You should think about wrapping the addJob() function in a promise:

  const doSomethingAndReturn = () => {
    return new Promise<string>((resolve, reject) => {
      Queue.addJob({
        task: () => doSomething().then(result => resolve(result)),
      });
    });
  };

Which you can then use elsewhere like so...

const result = await doSomethingAndReturn()

Note

If you're on react for the web, you can use this queue in your ServiceWorker to do tasks on a background thread. If you're using react-native like me, this will execute on the main JS thread, unless the job you're passing spawns it's own thread, like react-native-ffmpeg does for example.

TODO

  • Add a built in WebWorker option for web-based use
  • Add automated tests
  • Automate deployment to NPM
  • Automate & host example
  • Add arbitrary user data to tasks to allow users to track and organize tasks as they're queued and completed