Skip to content

Instantly share code, notes, and snippets.

@blabadi
Created September 9, 2018 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blabadi/56b57ec911d9eb4746921780e895592d to your computer and use it in GitHub Desktop.
Save blabadi/56b57ec911d9eb4746921780e895592d to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
class SearchBox extends Component {
state = {
term: ''
};
onTermChange = (e) => {
e.preventDefault();
const value = e.target.value;
this.setState({term : value});
this.props.onTermChange(value);
}
render() {
return (
<div className="card">
<div className="card-header">{this.props.title}</div>
<div className="card-body">
<div>
<input
className="form-control"
placeholder={this.props.placeholderText}
value={this.state.term}
onChange={this.onTermChange} />
</div>
<div className="search-results">
{
this.props.results.map(r => {
return <div key={r.key} className="result-row">{r.text}</div>
})
}
</div>
</div>
</div>
);
}
}
export default SearchBox;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment