1.1.62 • Published 4 years ago

use-debounced-effect-hook v1.1.62

Weekly downloads
1,562
License
MIT
Repository
github
Last release
4 years ago

use-debounced-effect-hook

useEffect hook from ReactJS debounced!

NPM JavaScript Style Guide

This implements a debounce action to the useEffect hook we all know, making it possible to execute debounced effects!

If you want to run some code everytime one variable changes, but not repeatedly (e.g. wait for the user to finish typing), this is the package for you =).

Online Example

You can check this hook running in this page.

Install

You can use yarn or npm. Whatever floats your boat =).

Yarn

yarn add use-debounced-effect-hook

npm

npm install --save use-debounced-effect-hook

Usage

You can also check example in this repo for more code!

import React, { useState } from 'react'

import useDebouncedEffect from 'use-debounced-effect-hook'

const App = () => {
  const [search, setSearch] = useState("");

  const searchInApi = (searchValue) => {
    // Do your API request here.
  };

  // This will only fire useEffect once in 1s (1000ms) when search changes.
  // This is done to prevent unnecessary code execution repeatedly.
  useDebouncedEffect(
    () => searchInApi(search),
    [ search ],
    1000, // The debounce delay
  );

  return (
    <>
      <input
        onChange={({target: { value }}) => setSearch(value)}
        type="text"
      />
    </>
  )
}

Contributing

Pull requests are welcome! If you have any feedback, issue or suggestion, feel free to open a new issue so we can talk about it 💬.

License

MIT © pedro-lb

Special Thanks

1.1.62

4 years ago

1.1.61

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago