-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(#77): remove input from tree page and add debounced input
- Loading branch information
1 parent
d8768ff
commit 39e20eb
Showing
3 changed files
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { useDebounce } from '../../hooks/useDebounce'; | ||
import { Input, InputProps } from '../ui/input'; | ||
|
||
interface IDebounceInput extends InputProps { | ||
interval: number; | ||
} | ||
|
||
const DebounceInput = ({ | ||
interval, | ||
onChange, | ||
...props | ||
}: IDebounceInput): JSX.Element => { | ||
const [inputEvent, setInputEvent] = | ||
useState<React.ChangeEvent<HTMLInputElement>>(); | ||
const eDebounced = useDebounce(inputEvent, interval); | ||
|
||
const onInputSearchTextChange = ( | ||
e: React.ChangeEvent<HTMLInputElement>, | ||
): void => { | ||
setInputEvent(e); | ||
}; | ||
|
||
useEffect(() => { | ||
if (eDebounced && onChange) onChange(eDebounced); | ||
}, [eDebounced, onChange]); | ||
|
||
return <Input {...props} onChange={onInputSearchTextChange} />; | ||
}; | ||
|
||
export default DebounceInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters