// @flow import React, { useEffect, useState } from 'react'; import { FormField } from 'component/common/form'; import Icon from 'component/common/icon'; import useDebounce from 'effects/use-debounce'; import classnames from 'classnames'; const FILTER_DEBOUNCE_MS = 300; interface Props { defaultValue?: string; icon?: string; placeholder?: string; inline?: boolean; onChange: (newValue: string) => any; } export default function DebouncedInput(props: Props) { const { defaultValue = '', icon, placeholder = '', inline, onChange } = props; const [rawValue, setRawValue] = useState(defaultValue); const debouncedValue: string = useDebounce(rawValue, FILTER_DEBOUNCE_MS); useEffect(() => { onChange(debouncedValue); }, [onChange, debouncedValue]); return (
{icon && } setRawValue(e.target.value.trim())} />
); }