From 09b437c4d3d133e319846638a7bebb5b8b1fc5ba Mon Sep 17 00:00:00 2001 From: Nik Date: Fri, 7 Jun 2024 19:22:06 +0100 Subject: [PATCH] add useDebounce returning data better explanation --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 6bd8682..f6aab47 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,16 @@ const rootElement = document.getElementById('root'); ReactDOM.render(, rootElement); ``` +The same API is available for `useDebounce` calls: +```js +const [value, {cancel, isPending, flush}] = useDebounce(valueToDebounce); +... +cancel() // cancels pending debounce request +isPending() // returns if there is a pending debouncing request +flush() // immediately flushes pending request +``` + + #### Flush method `useDebouncedCallback` has `flush` method. It allows to call the callback manually if it hasn't fired yet. This method is handy to use when the user takes an action that would cause the component to unmount, but you need to execute the callback.