Skip to content

Commit

Permalink
perf(searchbox): Memoize onChange handler
Browse files Browse the repository at this point in the history
  • Loading branch information
joerideg committed Jul 29, 2024
1 parent 25e4c28 commit 07d3fa7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/search/search-box/search-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useContext,
useEffect,
useState,
useCallback,
} from 'react';

import { debounce } from '../../utils/debounce';
Expand Down Expand Up @@ -56,9 +57,9 @@ export const SearchBox = forwardRef(
setQuery(event.target.value);
}, debounceDelay ?? 500);

const onChange = (event: ChangeEvent<HTMLInputElement>) => {
const onChange = useCallback((event: ChangeEvent<HTMLInputElement>) => {
debouncedSetQuery(event);
};
}, [debouncedSetQuery]);

return (
<>
Expand Down

0 comments on commit 07d3fa7

Please sign in to comment.