useDebounced<T> function

T? useDebounced<T>(
  1. T toDebounce,
  2. Duration timeout
)

Returns a debounced version of the provided value toDebounce, triggering widget updates accordingly after a specified timeout duration.

Example:

String userInput = ''; // Your input value

// Create a debounced version of userInput
final debouncedInput = useDebounced(
  userInput,
  Duration(milliseconds: 500), // Set your desired timeout
);
// Assume a fetch method fetchData(String query) exists
useEffect(() {
  fetchData(debouncedInput); // Use debouncedInput as a dependency
  return null;
}, [debouncedInput]);

Implementation

T? useDebounced<T>(
  T toDebounce,
  Duration timeout,
) {
  return use(
    _DebouncedHook(
      toDebounce: toDebounce,
      timeout: timeout,
    ),
  );
}