blob: a79100cd112f77a21714a81c864ea9491f053541 (
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
|
import React from 'react';
import PropTypes from 'prop-types';
import ReactRouterPropTypes from 'react-router-prop-types';
import { withRouter } from 'react-router-dom';
import { useFormState } from 'react-use-form-state';
function SearchBox({ onSearch, history, pathname }) {
let onSubmit = (event) => {
event.preventDefault();
onSearch(history, pathname, formState.values.search);
};
const [formState, { text }] = useFormState();
return (
<form onSubmit={onSubmit}>
<input name="search" className="text"
placeholder="Search..." value={ formState.values.search } {...text('search')} />
</form>
);
}
SearchBox.propTypes = {
pathname: PropTypes.string.isRequired,
onSearch: PropTypes.func.isRequired,
history: ReactRouterPropTypes.history.isRequired
};
export default withRouter(SearchBox);
|