mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
* 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
21 lines
668 B
TypeScript
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;
|
|
}
|