Skip to content

Commit

Permalink
add useDebounce returning data better explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
xnimorz committed Jun 7, 2024
1 parent e84bac1 commit 09b437c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ const rootElement = document.getElementById('root');
ReactDOM.render(<Input defaultValue="Hello world" />, 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.
Expand Down

0 comments on commit 09b437c

Please sign in to comment.