Skip to content

Commit

Permalink
[P2PS-3015]/Nada/fix: cannot access t before initialization (binary-c…
Browse files Browse the repository at this point in the history
…om#15452)

* fix: cannot access t before initialization

* fix: move timeout to ref
  • Loading branch information
nada-deriv committed Jun 4, 2024
1 parent 6e8fc27 commit f1f74af
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/components/src/components/search-box/search-box.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Icon from '../icon';
import Input from '../input';

const SearchBox = ({ className, onClear, onSearch, placeholder }) => {
const typing_timer = React.useRef(null);
const onSearchClear = setFieldValue => {
setFieldValue('search', '');

Expand All @@ -15,9 +16,9 @@ const SearchBox = ({ className, onClear, onSearch, placeholder }) => {
};

const onSearchKeyUpDown = submitForm => {
clearTimeout(typing_timer);
clearTimeout(typing_timer.current);

const typing_timer = setTimeout(() => {
typing_timer.current = setTimeout(() => {
submitForm();
}, 500);
};
Expand All @@ -35,6 +36,10 @@ const SearchBox = ({ className, onClear, onSearch, placeholder }) => {
}
};

React.useEffect(() => {
return () => clearTimeout(typing_timer.current);
}, []);

return (
<div className={classNames('search-box', className)}>
<Formik initialValues={{ search: '' }} onSubmit={onSearchSubmit}>
Expand Down

0 comments on commit f1f74af

Please sign in to comment.