blob: 314b89fb95501d903b6c3bede0eb321e83e36709 (
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
34
35
36
37
38
39
|
import React from 'react';
import PropTypes from 'prop-types';
import ReactRouterPropTypes from 'react-router-prop-types';
import { withRouter } from 'react-router-dom';
class SearchBox extends React.Component {
constructor(props) {
super(props);
this.state = {
search: ''
};
}
handleChange = (event) => {
this.setState({
search: event.target.value
});
}
onSubmit = (event) => {
const { history, pathname } = this.props;
event.preventDefault();
this.props.onSearch(history, pathname, 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 = {
pathname: PropTypes.string.isRequired,
onSearch: PropTypes.func.isRequired,
history: ReactRouterPropTypes.history.isRequired
};
export default withRouter(SearchBox);
|