Skip to content

FEAT: useDebounce a custom debounce hook#5

Open
olayemii wants to merge 4 commits intokenshinman:devfrom
olayemii:dev
Open

FEAT: useDebounce a custom debounce hook#5
olayemii wants to merge 4 commits intokenshinman:devfrom
olayemii:dev

Conversation

@olayemii
Copy link
Copy Markdown

@olayemii olayemii commented Jun 5, 2020

To use this hook

  1. Import useDebounce to your component.

  2. Destruct the debouncer const [debouncer] = useDebounce(1000) // 1000 is the debounce delay

  3. Debounce delay is OPTIONAL, defaults to 1000

To debounce any method, send the method as a parameter to your debouncer e.g.
debouncer(() => console.log(1+1)) //the result will be logged after 1000ms

MOTIVATION This was made to delay server calls when making searches, instead of making a request on every keystroke, we debounce to a delayed time after the last keystroke.

A storybook example is included for testing this hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant