Skip to content

Instantly share code, notes, and snippets.

@kartikag01
Created July 24, 2019 05:20
Show Gist options
  • Save kartikag01/b2eba7532b9e1fe048eb07c2bf5962d0 to your computer and use it in GitHub Desktop.
Save kartikag01/b2eba7532b9e1fe048eb07c2bf5962d0 to your computer and use it in GitHub Desktop.
TrendingRepo debounce
function TrendingRepo() {
const [repos, setRepos] = React.useState([]);
const debounceOnChange = React.useCallback(debounce(onChange, 400), []);
function onChange(value) {
fetch(`https://github-trending-api.now.sh/repositories?language=${value}`)
.then(res => res.json())
.then(res => setRepos(res));
}
return (
<div className="App">
<h1>Search Trending Repo, via Language</h1>
<input
className="filter-input"
placeholder="Language: Java, JavaScript, Ruby, Python"
onChange={e => debounceOnChange(e.target.value)}
/>
<List trendingRepos={repos} />
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment