aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/SearchBox.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-28 00:23:40 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:58 +0300
commit9bd48005fda1d94a526e36bec256b56add65b28d (patch)
tree2bffeb7e3ec8b2e8ac6886cffae544771958e333 /vnext/src/ui/SearchBox.js
parent40d411e516efee5531404725b45ab89d97172ce8 (diff)
use `react-hook-form` and fix tests
Diffstat (limited to 'vnext/src/ui/SearchBox.js')
-rw-r--r--vnext/src/ui/SearchBox.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/vnext/src/ui/SearchBox.js b/vnext/src/ui/SearchBox.js
index c79c9e8f..e6085fdc 100644
--- a/vnext/src/ui/SearchBox.js
+++ b/vnext/src/ui/SearchBox.js
@@ -1,4 +1,4 @@
-import { useFormState } from 'react-use-form-state';
+import { useForm } from 'react-hook-form';
/**
* @typedef {Object} SearchBoxPropsFields
@@ -13,15 +13,16 @@ import { useFormState } from 'react-use-form-state';
* @param {SearchBoxProps} props
*/
function SearchBox({ onSearch }) {
- let onSubmit = (/** @type React.FormEvent<HTMLFormElement> */ event) => {
- event.preventDefault();
- onSearch(formState.values.search);
+ const { register, handleSubmit, formState: { errors }, } = useForm();
+ /** @type { import('react-hook-form').SubmitHandler<import('react-hook-form').FieldValues> } */
+ let onSubmit = ( values ) => {
+ onSearch(values.search);
};
- const [formState, { text }] = useFormState();
return (
- <form onSubmit={onSubmit}>
- <input name="search" className="text"
- placeholder="Search..." value={formState.values.search} {...text('search')} />
+ <form onSubmit={handleSubmit(onSubmit)}>
+ <input className="text" type="text"
+ placeholder="Search..." {...register('search')} />
+ <input data-testid="submit" type="submit" hidden />
</form>
);
}