Skip to content

Instantly share code, notes, and snippets.

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