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

query-debounce

v2.4.2

Published

Query Debounce is a custom hook designed to facilitate the management of multiple inputs that can be debounced

Downloads

30

Readme

npm licence minzip npm downloads

Query Debounce

Query Debounce is a custom hook designed to facilitate the management of multiple inputs that can be debounced in the form of an object, making it easier to manage numerous query parameters to avoid unnecessary repeated calls to the server (API).

Features

  • Facilitates debouncing for multiple inputs (state object).
  • Can retrieve values without debounce (callback on set value).
  • Provides progress status for change, loading, or success.
  • Returns are available for set value, set value bulk, get, watch, actual aatch, clear, and register.

Installation

With npm

npm install query-debounce

With yarn

yarn add query-debounce

With pnpm

pnpm add query-debounce

Quickstart

import { useQueryDebounce } from "query-debounce";
const App = () => {
  const { register, getValues, getValidValues, watch } = useQueryDebounce({
    defaultValues: {
      name: "",
      status: "",
    },
    wait: 500,
  });

  // Get all values
  console.log(getValues());
  // Get all valid values
  console.log(getValidValues());
  // Get value by key
  console.log(watch("name"));

  return (
    <div>
      <label htmlFor="name">Name:</label>
      <input id="name" type="text" {...register("name")} />
      <label htmlFor="status">status:</label>
      <input id="status" type="text" {...register("status")} />
    </div>
  );
};

export default App;

Documentation

useQueryDebounce: (options) => Return

Query Debounce is a custom hook for creating debounced states.

Options

The options for useQueryDebounce are as follows:

• defaultValues

• onProgress

• onSuccess

• wait

defaultValues: DefaultValue | () => TDefaultValue

defaultValues is used to set default values for an object or a function that returns data.


onProgress: (status, totalTimer) => void

onProgress is used to capture the progress during the debounce wait process.

Props

status: loading | success

Fetching the value of progress status.

totalTimer

Fetching the total wait timer.


onSuccess: (data) => void

onSuccess will be called when the setValue process succeeds.

Props

data: TDefaultValue

Fetching data in the form of an object.


wait: number

wait is used to set the waiting time before the setValue is executed, default value: 500ms.


Returns

The return from useQueryDebounce is as follows:

• getValues

• getValidValues

• getActualValues

• setValue

• setBulkValues

• clearValues

• register

• actualWatch

• watch

• reset


getValues: () => TDefaultValue

getValues is used to fetch all values of the object.


getValidValues: () => Partial<TDefaultValue>

getValidValues is used to fetch all valid values of the object.

getActualValues: () => Partial<TDefaultValue>

getUnbouncedValue is used to fetch all values without debounce of the object..


setValue: (key, value, callback) => void

setValue is used to set a value.

Props

key: keyof TDefaultValue

key is the key of the object for which you want to set a value.

value: Partial<TDefaultValue>[keyof TDefaultValue]

value is the value you want to set according to the key.

callback?: (data: Partial<TDefaultValue>) => void

callback is used to fetch all values before setting a new value.


setBulkValues: (values, callback) => void

setBulkValues is used to set multiple values at once.

Props

values: Partial<TDefaultValue>

values is the object for which you want to set the bulk values.

callback?: (data: Partial<TDefaultValue>) => void

callback is used to fetch all values before setting a new value.


clearValues: (key) => void

clearValues is used to delete values that have been stored based on the key.

Props

key: keyof TDefaultValue | Array<keyof TDefaultValue>

key is the key of the object that you want to delete.


register: (key) => { onChange}

register is used to associate this registration with the returned onChange object for the registered input

Props

key: keyof TDefaultValue

key is the key of the object you want to register.

Return
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void

onChange is used to perform a value change


actualWatch: (key, calback) => void

watch is used to fetch actual values based on the key.

watch: (key, calback) => void

watch is used to fetch values based on the key.

Props

key: keyof TDefaultValue

key is the key of the object you want to retrieve.

calback?: ((data: Partial<TDefaultValue>) => void) | undefined)

callback is used to fetch all values within the watch function.


reset: () => void

reset is used to reset the value to the default values.

Good luck, have fun!

Let me know if u have feedback, thanks