Files
outline/app/hooks/useDebouncedValue.ts
T
Tom Moor 6a6987ec2d perf: Faster mention suggestions (#14583)
* perf: Faster mention suggestions

Limit each section of suggestions.mention to 1s so a slow query does not
delay the others, debounce mention and link editor requests, ignore stale
responses, and use title search in the link editor.

* fix: Include presentation in the mention suggestion time limits

* test: Use a fixed name in the collection member name filter test
2026-11-13 22:37:49 -05:00

21 lines
668 B
TypeScript

import { useEffect, useState } from "react";
/**
* Returns a value that only changes after the given value has stayed the same
* for the wait time. The first value is returned at once.
*
* @param value the value to debounce.
* @param wait the time in milliseconds the value must stay the same.
* @returns the last value that stayed the same for the wait time.
*/
export default function useDebouncedValue<T>(value: T, wait: number): T {
const [debounced, setDebounced] = useState(value);
useEffect(() => {
const timeout = setTimeout(() => setDebounced(value), wait);
return () => clearTimeout(timeout);
}, [value, wait]);
return debounced;
}