1function SearchBar({ onSearch, debounceMs }) {
2 const debouncedSearch = useCallback(
3 debounce((query) => {
4 onSearch(query);
5 }, debounceMs),
6 [] // missing onSearch and debounceMs
7 );
8
9 return <input onChange={e => debouncedSearch(e.target.value)} />;
10}
no lines flagged
#049PracticeMedium18 min · 120 XP
useCallback Captures Stale Props
A memoized event handler always uses the initial prop value because the dependency array is empty.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.