mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
31 lines
885 B
TypeScript
31 lines
885 B
TypeScript
import { useState, useEffect } from 'react';
|
|
|
|
/**
|
|
* Custom hook that debounces a value.
|
|
* @param value The value to be debounced.
|
|
* @param delay The delay in milliseconds.
|
|
* @returns The debounced value.
|
|
*/
|
|
export const useDebounce = <T>(value: T, delay: number): T => {
|
|
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
|
|
|
useEffect(
|
|
() => {
|
|
// Set debouncedValue to value (passed in) after the specified delay
|
|
const handler = setTimeout(() => {
|
|
setDebouncedValue(value);
|
|
}, delay);
|
|
|
|
// Return a cleanup function that will be called every time ...
|
|
// ... useEffect is re-called. useEffect will be re-called ...
|
|
// ... if value or delay changes.
|
|
return () => {
|
|
clearTimeout(handler);
|
|
};
|
|
},
|
|
[value, delay] // Only re-call effect if value or delay changes
|
|
);
|
|
|
|
return debouncedValue;
|
|
};
|