10LOC

#debounce

Node.jsintermediate

A debounced fs.watch file watcher, no chokidar

import { watch } from "node:fs";

export const watchDebounced = (path: string, onChange: (eventType: string) => void, waitMs = 200) => {
  let timer: NodeJS.Timeout | undefined;

fs.watch fires multiple times for a single logical change; debouncing it with a plain setTimeout gets you chokidar's core behavior for free.

Reactintermediate

A 10-line useDebouncedValue custom hook

import { useState, useEffect } from "react";

export const useDebouncedValue = <T,>(value: T, delayMs: number): T => {
  const [debounced, setDebounced] = useState(value);

Debounce a fast-changing value, like search input, without redefining a timer effect in every component that needs one.