Created
July 24, 2019 05:20
-
-
Save kartikag01/b2eba7532b9e1fe048eb07c2bf5962d0 to your computer and use it in GitHub Desktop.
TrendingRepo debounce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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