Skip to content

Commit 732a336

Browse files
committed
added debounce to throttle user input searching
1 parent 0daf6a1 commit 732a336

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/index.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component } from 'react';
22
import ReactDOM from 'react-dom';
3+
import _ from 'lodash';
34
import YTSearch from 'youtube-api-search';
45
import SearchBar from './components/search_bar';
56
import VideoList from './components/video_list';
@@ -31,15 +32,16 @@ class App extends Component {
3132
}
3233

3334
render() {
34-
return (
35-
<div>
36-
<SearchBar handleSearchTermChange={ term => this.videoSearch(term)} />
37-
<VideoDetail video={ this.state.selectedVideo }/>
38-
<VideoList
39-
handleVideoSelect={ selectedVideo => this.setState({ selectedVideo }) }
40-
videos= { this.state.videos }/>
41-
</div>
42-
);
35+
const videoSearch = _.debounce((term) => { this.videoSearch(term)}, 300);
36+
return (
37+
<div>
38+
<SearchBar handleSearchTermChange={ videoSearch } />
39+
<VideoDetail video={ this.state.selectedVideo }/>
40+
<VideoList
41+
handleVideoSelect={ selectedVideo => this.setState({ selectedVideo }) }
42+
videos= { this.state.videos }/>
43+
</div>
44+
);
4345
}
4446
};
4547

0 commit comments

Comments
 (0)