Coder Social home page Coder Social logo

eavam / use-debouncy Goto Github PK

View Code? Open in Web Editor NEW
44.0 1.0 3.0 200.41 MB

πŸŒ€ Small (~0.2kb) debounce effect hook for React with TypeScript support

Home Page: https://npmjs.com/package/use-debouncy

License: MIT License

TypeScript 92.54% JavaScript 4.39% HTML 2.04% Shell 1.03%
debounce react-hooks typescript hooks effects react support-typescript hook tiny requestanimationframe

use-debouncy's Introduction

useDebouncy

πŸŒ€ Small (~0.2kb) debounce effect hook for React with TypeScript support

GitHub npm bundle size npm types codecov FOSSA Status

Features

  • πŸ‘Œ No dependencies.
  • πŸ‹οΈβ€ Tiny. ~0.2kb.
  • 🦾 Performance. Used by requestAnimationFrame.
  • πŸ“– Types. Support TypeScript.
  • 🎣 Easy. Use like React effect or function.

Installation

NPM

npm install use-debouncy

Yarn

yarn add use-debouncy

Usage

Use as effect hook

import React, { useState } from 'react';
import { useDebouncyEffect } from 'use-debouncy';

const App = () => {
  const [value, setValue] = useState('');

  useDebouncyEffect(
    () => fetchData(value), // function debounce
    400, // number of milliseconds to delay
    [value], // array values that the debounce depends (like as useEffect)
  );

  return <input value={value} onChange={(event) => setValue(event.target.value)} />;
};

Use as callback function

import React, { useState } from 'react';
import { useDebouncyFn } from 'use-debouncy';

const App = () => {
  const handleChange = useDebouncyFn(
    (event) => fetchData(event.target.value), // function debounce
    400, // number of milliseconds to delay
  );

  return <input value={value} onChange={handleChange} />;
};

API Reference

useDebouncy/effect

function useDebouncyEffect(fn: () => void, wait?: number, deps?: any[]): void;
Prop Required Default Description
fn βœ“ Debounce callback.
wait 0 Number of milliseconds to delay.
deps [] Array values that the debounce depends (like as useEffect).

useDebouncy/fn

function useDebouncyFn(fn: (...args: any[]) => void, wait?: number): (...args: any[]) => void;
Prop Required Default Description
fn βœ“ Debounce handler.
wait 0 Number of milliseconds to delay.

Development

js-standard-style

License

FOSSA Status

use-debouncy's People

Contributors

dependabot[bot] avatar fossabot avatar imgbotapp avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

use-debouncy's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@github.com/egorAva/use-debouncy.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Support react 18

β–Ά npm i -SE use-debouncy  
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"18.2.0" from [email protected]
npm ERR!   packages/client
npm ERR!     [email protected]
npm ERR!     node_modules/client
npm ERR!       workspace packages/client from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from [email protected]
npm ERR! node_modules/use-debouncy
npm ERR!   use-debouncy@"*" from [email protected]
npm ERR!   packages/client
npm ERR!     [email protected]
npm ERR!     node_modules/client
npm ERR!       workspace packages/client from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/marcusstenbeck/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/marcusstenbeck/.npm/_logs/2022-09-08T20_39_11_326Z-debug-0.log

Disable "postinstall" script in published package

Hello.

First of all, thank you for your package.

I am having issue installing it as a dependency since your postinstall script is executed and so tries to install husky (which fails since the command is not run in my project root directory).
My understanding is that you should use prepare instead of postinstall (if using npm) or use pinst to to disable postinstall when publishing your package.

Let me know if I missed something.

Thanks,

Nicolas

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No NPM access token specified.

A NPM access token must be provided in your configuration. The token must allow to publish to the registry "https://registry.npmjs.org/".

Please refer to the npm registry authentication section of the README to learn how to configure the NPM registry access token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

This expression is not callable.

This expression is not callable.
Type 'typeof import("./node_modules/use-debouncy/lib/index")' has no call signatures.ts(2349)

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm rollup-plugin-terser Available

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency @playwright/test to v1.46.1
  • chore(deps): update dependency @vitejs/plugin-react to v4.3.1
  • chore(deps): update dependency eslint-plugin-import to v2.29.1
  • chore(deps): update dependency eslint-plugin-n to v16.6.2
  • chore(deps): update dependency eslint-plugin-promise to v6.6.0
  • chore(deps): update dependency eslint-plugin-react to v7.35.0
  • chore(deps): update dependency fast-check to v3.21.0
  • chore(deps): update dependency pretty-quick to v3.3.1
  • chore(deps): update dependency ts-jest to v29.2.5
  • chore(deps): update dependency vite to v4.5.3
  • chore(deps): update dependency vite-plugin-commonjs to v0.10.1
  • chore(deps): update jest update to v29.7.0 (jest, jest-environment-jsdom)
  • chore(deps): update react monorepo (@types/react, @types/react-dom, eslint-plugin-react-hooks)
  • chore(deps): update react update to v18.3.1 (react, react-dom)
  • chore(deps): update semantic-release monorepo (@semantic-release/commit-analyzer, @semantic-release/github, @semantic-release/npm, @semantic-release/release-notes-generator, semantic-release)
  • chore(deps): update yarn to v3.8.5
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update actions/upload-artifact action to v4
  • chore(deps): update codecov/codecov-action action to v4
  • chore(deps): update commitlint monorepo to v19 (major) (@commitlint/cli, @commitlint/config-conventional)
  • chore(deps): update dependency @rollup/plugin-commonjs to v26
  • chore(deps): update dependency @testing-library/react to v16
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency eslint-plugin-n to v17
  • chore(deps): update dependency eslint-plugin-prettier to v5
  • chore(deps): update dependency eslint-plugin-promise to v7
  • chore(deps): update dependency husky to v9
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency pretty-quick to v4
  • chore(deps): update dependency rimraf to v6
  • chore(deps): update dependency rollup to v4
  • chore(deps): update dependency semantic-release-yarn to v3
  • chore(deps): update dependency typescript to v5
  • chore(deps): update dependency vite to v5
  • chore(deps): update semantic-release monorepo (major) (@semantic-release/commit-analyzer, @semantic-release/github, @semantic-release/npm, @semantic-release/release-notes-generator, semantic-release)
  • chore(deps): update typescript-eslint monorepo to v8 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • chore(deps): update yarn to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build-and-test.yml
  • actions/checkout v3
  • actions/setup-node v3
  • codecov/codecov-action v3
  • actions/upload-artifact v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/upload-artifact v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/upload-artifact v3
npm
.yarn/sdks/eslint/package.json
.yarn/sdks/prettier/package.json
.yarn/sdks/typescript/package.json
package.json
  • @commitlint/cli 17.8.1
  • @commitlint/config-conventional 17.8.1
  • @playwright/test 1.45.3
  • @rollup/plugin-commonjs 25.0.8
  • @rollup/plugin-sucrase 5.0.2
  • @semantic-release/changelog 6.0.3
  • @semantic-release/commit-analyzer 11.0.0
  • @semantic-release/exec 6.0.3
  • @semantic-release/git 10.0.1
  • @semantic-release/github 9.0.6
  • @semantic-release/npm 11.0.0
  • @semantic-release/release-notes-generator 12.0.0
  • @testing-library/react 14.3.1
  • @types/jest 29.5.12
  • @types/react 18.0.28
  • @types/react-dom 18.0.11
  • @typescript-eslint/eslint-plugin 5.62.0
  • @typescript-eslint/parser 5.62.0
  • @vitejs/plugin-react 4.2.1
  • eslint 8.57.0
  • eslint-config-prettier 8.10.0
  • eslint-config-standard 17.1.0
  • eslint-plugin-import 2.27.5
  • eslint-plugin-n 16.0.2
  • eslint-plugin-prettier 4.2.1
  • eslint-plugin-promise 6.1.1
  • eslint-plugin-react 7.32.2
  • eslint-plugin-react-hooks 4.6.0
  • fast-check 3.12.0
  • husky 8.0.3
  • jest 29.6.4
  • jest-environment-jsdom 29.6.4
  • prettier 2.8.8
  • pretty-quick 3.1.3
  • react 18.2.0
  • react-dom 18.2.0
  • rimraf 5.0.10
  • rollup 3.29.4
  • rollup-plugin-terser 7.0.2
  • semantic-release 22.0.0
  • semantic-release-yarn 2.0.2
  • ts-jest 29.1.5
  • ts-node 10.9.2
  • typescript 4.9.5
  • vite 4.4.9
  • vite-plugin-commonjs 0.8.2
  • react ^16.8.0 || ^17.0.0 || ^18.0.0
  • yarn 3.6.3
test-publish/package.json

  • Check this box to trigger a request for Renovate to run again on this repository

renderFrame is using `Date.now` to initialize the callback start time instead of requestAnimationFrame first argument

Hi,

I think there is a bug in latest version that is reproduced here: https://codesandbox.io/s/reproduce-use-debouncy-bug-yx40d
You'll notice that nothing appears in the console when you're typing in the input text.

My guess is that you're using Date.now() to setup timeStart argument of renderFrame callback whereas window.requestAnimationFrame() method is passing a DOMHighResTimeStamp (similar to the one returned by performance.now()) as the single argument to the callback function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.