Skip to content

Commit c714a80

Browse files
committed
[FIX] useThrottle hook
1 parent 8aad296 commit c714a80

5 files changed

Lines changed: 5602 additions & 11 deletions

File tree

apps/react-tools-demo/src/markdown/isAsync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ isAsync <T extends unknown[], E = unknown>(fn: (...args: T)=> E | Promise<E>): b
99
1010
> ### Params
1111
>
12-
>
12+
> - ____: _(...args: unknown[])=> Eìunknown | Promise<unknown>_
1313
>
1414
1515
> ### Returns

apps/react-tools-demo/src/markdown/useThrottle.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Hook to limit function execution frequency.
77
export const UseThrottle = () => {
88
const [state, setState] = useState(0);
99
const [fn, cancel, immediate] = useThrottle(
10-
useCallback(() => setState(t => t+1), []),
10+
useCallback(() => new Promise(res => setTimeout(() => res(setState(t => t + 1)), 3000)), []),
1111
{
12-
delay: 3000
12+
waitFn: true
1313
}
1414
);
1515

@@ -26,10 +26,8 @@ export const UseThrottle = () => {
2626
```
2727

2828
> The component has:
29-
> - A _state_ internal state.
30-
> - A _toggle_ internal state used to choice which function execute on the OnChange event of the input element.
31-
> - A _useDebounce_ hook that receives a function that updates _state_ variable with input element value and a delay of 1000ms. It returns the debounced function _fn_, the function to cancel debounced function execution _cancel_ and the function to immediately execute function _immediate_.
32-
> - A _useCallback_ setted as Onchange function of the input element that executes _fn_ or _immediate_ to handle onChange, by _toggle_ value.
29+
> - A _state_ internal with _0_ value.
30+
> - A _useThrottle_ hook that receives an async function that increments _state_ variable after 3 seconds and _waitFn_ true as option. It returns the debounced function _fn_, the function to cancel throttle limitation _cancel_ and the function _immediate_ to immediately execute function. Each function is executed by onClick event of three button elements.
3331
3432

3533
## API

0 commit comments

Comments
 (0)