0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

lodash-es (lodash) のdebounce関数

Last updated at Posted at 2024-07-28

lodash-es (lodash) の debounce 関数は、特定の時間が経過するまで関数の実行を遅延させるためのもの

例えば、ユーザーが入力を停止してから一定時間後にサーバーへリクエストを送信する場合に便利。

import { debounce } from 'lodash-es';

const debouncedFunction = debounce(() => {
  // 実行したい処理(サーバーへのリクエストなど)
}, 1000); // 1秒の遅延

// イベントリスナーに適用
element.addEventListener('input', debouncedFunction);

ユーザー入力毎にリクエストを送信するのは効率悪いですもんね。

詳しくはリファレンスを見てね。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?