Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Created February 25, 2021 08:18
Show Gist options
  • Save rcdexta/fa47413a2f39c5791e1ad868c3440efc to your computer and use it in GitHub Desktop.
Save rcdexta/fa47413a2f39c5791e1ad868c3440efc to your computer and use it in GitHub Desktop.
const App = () => {
const [results, setResults] = React.useState([]);
const debouncedHandler = debounce((term) => {
if (term) {
axios
.get(`https://ticker-2e1ica8b9.now.sh/keyword/${term}`)
.then((res) => {
setResults(res.data);
});
} else setResults([]);
}, 500);
const onInput = debounce((e) => {
e.persist();
debouncedHandler(e.target.value);
}, 500);
return (
<div className="App">
<h1>Search Stock Ticker</h1>
<input type="text" onChange={onInput} />
<div className="Results">
{results.map((r) => (
<div>
{r.name} [{r.symbol}]
</div>
))}
</div>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment