1.0.7 • Published 7 months ago

@tater-archives/react-use-debounce v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

react-use-debounce

Several utilities to debounce functions, preventing rapid calling of functions.

useDebounce

Creates a "debounced" version of a function which is only called after the debounced version is not called for a specified amount of time. Useful for inputs where the onChange uses a lot of processing.

Note: useDebounce expects the function to not change frequently. If the supplied function is a literal, wrap it in useCallback.

Example Usage

const handleChange = useDebounce(expensiveSetter, 500);
// `onChange` will only be called if `expensiveSetter`
/// is not called for 500 milliseconds (0.5 seconds)

<input onChange={handleChange} />

useUnsafeDebounce

Has the same functionality as useDebounce but doesn't call the function if the component unmounts, in exchange for less overhead.

useDebouncedState

Maintains an internal state that is always up-to-date and debounces it to an external state. Useful if you need a controlled component but still want to debounce the state.

Example Usage

const [state, setState] = useDebouncedState(externalState, expensiveSetter, 500);

// ExampleComponent will update with new values but expensiveSetter
// will not be called until it stops being set for 500 milliseconds
<ExampleComponent value={state} onChange={setState} />
1.0.7

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago