Skip to content

Commit

Permalink
Fix search input change
Browse files Browse the repository at this point in the history
  • Loading branch information
pclavier92 committed Oct 9, 2020
1 parent 70c4a72 commit f044d78
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/client/pages/radio/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { debounce } from 'Utils';
import SearchBar from './search-bar';
import SearchList from './search-list';

const ONE_SECOND = 1000; // ms
const HALF_SECOND = 500; // ms

const Search = ({ playedSongs, radioQueue }) => {
const [searchInput, setSearchInput] = useState('');
Expand All @@ -21,7 +21,7 @@ const Search = ({ playedSongs, radioQueue }) => {
}
} = await spotifyWebApi.getSearchResults(searchInput);
setSearchResults(items);
});
}, [searchInput]);

useEffect(() => {
(async () => {
Expand All @@ -38,11 +38,14 @@ const Search = ({ playedSongs, radioQueue }) => {
if (searchInput !== '') {
triggerSearch();
}
}, [searchInput]);
}, [searchInput, triggerSearch]);

const onSearchInputChange = useCallback(() => {
debounce(setSearchInput, ONE_SECOND);
});
const onSearchInputChange = useCallback(
debounce(value => {
setSearchInput(value);
}, HALF_SECOND),
[]
);

return (
<div className="radio-search">
Expand Down

0 comments on commit f044d78

Please sign in to comment.