diff --git a/src/components/source/SourceOptions.tsx b/src/components/source/SourceOptions.tsx index 736ac0da..2d4355ee 100644 --- a/src/components/source/SourceOptions.tsx +++ b/src/components/source/SourceOptions.tsx @@ -56,7 +56,7 @@ export function Options({ sourceFilter, group, updateFilterValue, update }: IFil = (props) => { const { state, name, position, group, updateFilterValue, update } = props; const [Search, setsearch] = React.useState(state || ''); - let typingTimer: NodeJS.Timeout; + const inputText = useDebounce(Search, 500); - function doneTyping(e: React.ChangeEvent) { + useEffect(() => { const upd = update.filter( (el: { position: number; group: number | undefined }) => !(position === el.position && group === el.group), ); - updateFilterValue([...upd, { position, state: e.target.value, group }]); - } - - function handleChange(e: React.ChangeEvent) { - setsearch(e.target.value); - - clearTimeout(typingTimer); - typingTimer = setTimeout(() => { - doneTyping(e); - }, 2500); - } + updateFilterValue([...upd, { position, state: inputText, group }]); + }, [inputText]); if (state !== undefined) { return ( @@ -46,8 +38,8 @@ const TextFilter: React.FC = (props) => { {name} setsearch(value)} endAdornment={