PluginProbe
ElasticPress / 5.0.2
ElasticPress v5.0.2
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / assets / js / woocommerce / admin / orders / hooks.js

hooks.js in ElasticPress 5.0.2, at assets/js/woocommerce/admin/orders/hooks.js

28 lines 639 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies.
3 */
4 import { useCallback, useRef } from '@wordpress/element';
5
6 /**
7 * Get debounced version of a function that only runs a given amount of time
8 * after the last time it was run.
9 *
10 * @param {Function} callback Function to debounce.
11 * @param {number} delay Milliseconds to delay.
12 * @returns {Function} Debounced function.
13 */
14 export const useDebounce = (callback, delay) => {
15 const timeout = useRef(null);
16
17 return useCallback(
18 (...args) => {
19 window.clearTimeout(timeout.current);
20
21 timeout.current = window.setTimeout(() => {
22 callback(...args);
23 }, delay);
24 },
25 [callback, delay],
26 );
27 };
28