UNPKG

@lobehub/editor

Version:

A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.

22 lines 601 B
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import { debounce } from 'es-toolkit/compat'; import { useMemo, useRef } from 'react'; export function useDebounce(fn, ms, maxWait) { var funcRef = useRef(null); funcRef.current = fn; return useMemo(function () { return debounce(function () { if (funcRef.current) { funcRef.current.apply(funcRef, arguments); } }, ms, { maxWait: maxWait }); }, [ms, maxWait]); }