-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchBar.js
32 lines (30 loc) · 943 Bytes
/
SearchBar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import './SearchBar.css';
export class SearchBar extends React.Component {
constructor(props) {
super(props);
this.state = {
searchTerm: 'search term'
}
this.search = this.search.bind(this);
this.handleTermChange = this.handleTermChange.bind(this);
}
// pass state of the search term to `this.props.onSearch`
search() {
this.props.onSearch(this.state.searchTerm);
}
// set state of search bar's term to event targets value
handleTermChange(e) {
this.setState({
searchTerm: e.target.value
});
}
render() {
return (
<div className="SearchBar">
<input placeholder="Enter A Song, Album, or Artist" onChange={this.handleTermChange} />
<button className="SearchButton" onClick={this.search}>SEARCH</button>
</div>
);
}
}