Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

323 B
Raw Blame
import { useEffect, useState } from 'react';

export const useDebounceValue = <T>(value: T, delay: number): T => {
  const [state, setState] = useState(value);
  useEffect(() => {
    const handler = setTimeout(() => setState(value), delay);
    return () => clearTimeout(handler);
  }, [value, delay]);
  return state;
};