function useDebounce(value, delay) { const [debouncedValue, setDebouncedValue] = useState(value); useEffect(() => { const timer = setTimeout(() => { setDebouncedValue(value); }, delay); return () => { clearTimeout(timer); }; }, [value, delay]); return debouncedValue; } // Utilisation function SearchInput({ onSearch }) { const [query, setQuery] = useState(''); const debouncedQuery = useDebounce(query, 300); useEffect(() => { if (debouncedQuery) { onSearch(debouncedQuery); } }, [debouncedQuery, onSearch]); return ( setQuery(e.target.value)} placeholder="Rechercher..." /> ); }