const history = useHistory(); const location = useLocation(); const [currentPage, setCurrentPage] = useState(1); const [categoryItemIdLocal, setCategoryItemIdLocal] = useState(''); const [minPrice, setMinPrice] = useState(0); const [maxPrice, setMaxPrice] = useState(0); const [cityId, setCityId] = useState(0); const [text, setText] = useState(''); useEffect(() => { const params = new URLSearchParams(location.search); setCurrentPage(params.get('page') || 1); setMinPrice(params.get('min_price') || 0); setMaxPrice(params.get('max_price') || 0); setCityId(params.get('cities') || 0); setText(params.get('text') || ''); }, [location.search]); const handleSearch = () => { let url = `?page=${currentPage}`; if (minPrice > 0) { url += `&min_price=${minPrice}`; } if (maxPrice > 0) { url += `&max_price=${maxPrice}`; } if (cityId !== 0) { url += `&cities=${cityId}`; } if (text !== '') { url += `&text=${text}`; } history.push(url); };