blob: e64c8be48a993a863cadb7cea7d216f64fc11d94 (
plain) (
blame)
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
33
|
import React from 'react';
import PropTypes from 'prop-types';
export default class SearchBox extends React.Component {
constructor(props) {
super(props);
this.state = {
search: ''
};
}
handleChange = (event) => {
this.setState({
search: event.target.value
});
}
onSubmit = (event) => {
event.preventDefault();
this.props.onSearch(this.state.search);
this.setState({
search: ''
});
}
render() {
return (<form onSubmit={this.onSubmit}>
<input name="search" className="text"
placeholder="Search..." value={this.state.search} onChange={this.handleChange} />
</form>);
}
}
SearchBox.propTypes = {
onSearch: PropTypes.func.isRequired
};
|