blob: aab49757bd9bf4e5c31e8f2c6c1cfa2a36831b14 (
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
|
import React from 'react';
import { withRouter } from 'react-router-dom';
import { useFormState } from 'react-use-form-state';
/**
* @typedef {Object} SearchBoxPropsFields
* @property {string} pathname
* @property {function} onSearch
*/
/**
* @typedef {import('react-router-dom').RouteComponentProps & SearchBoxPropsFields} SearchBoxProps
*/
/**
* @param {SearchBoxProps} props
*/
function SearchBox({ onSearch, history, pathname }) {
/**
* @type {(React.FormEvent<HTMLFormElement>)}
*/
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>
);
}
export default withRouter(SearchBox);
|