import { InputAdornment, TextField } from '@mui/material'; import { memo, useEffect, useRef, useState } from 'react'; import { Search } from './icons/icons'; function SearchComponent({ placeholder = 'Поиск...', value = '', onChange, debounceMs = 0, height = '2rem', sx: sxProp, ...rest }) { const [inputValue, setInputValue] = useState(value); const onChangeRef = useRef(onChange); useEffect(() => { onChangeRef.current = onChange; }, [onChange]); useEffect(() => { setInputValue(value); }, [value]); useEffect(() => { if (!debounceMs) return; const timer = setTimeout(() => { if (inputValue !== value) { onChangeRef.current(inputValue); } }, debounceMs); return () => clearTimeout(timer); }, [inputValue, debounceMs, value]); const handleChange = (e) => { const next = e.target.value; setInputValue(next); if (!debounceMs) { onChange(next); } }; return ( ), }, }} /> ); } export default memo(SearchComponent);