Created
February 25, 2021 07:56
-
-
Save rcdexta/ada17a1c0f1fac545059c0abfdbaa149 to your computer and use it in GitHub Desktop.
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
class App extends React.Component { | |
state = { results: [] }; | |
onInput = (e) => { | |
const term = e.target.value; | |
if (term) { | |
axios | |
.get(`https://ticker-2e1ica8b9.now.sh/keyword/${term}`) | |
.then((res) => { | |
this.setState({ results: res.data }); | |
}); | |
} else this.setState({ results: [] }); | |
}; | |
render() { | |
return ( | |
<div className="App"> | |
<h1>Search Stock Ticker</h1> | |
<input type="text" onChange={this.onInput} /> | |
<div className="Results"> | |
{this.state.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