Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
React Router, Function not getting props

This logic is about filtering houses based on filters (such as purpose, price etc) when I change the filters nothing happens (no url change) or no error on console. It looks like data is not being passed to searchProperties.

I am unable to find any solution.

Note: Ignore comments.

import classes from "./FilterProperties.module.css";

import { useState } from "react";
import { filterData, getFilterValues } from "../../lib/filterData";
import {
  useLocation,useSearchParams, useNavigate} from "react-router-dom";

import DropDown from "./DropDown";

const FilterProperties = () => {
  const location = useLocation();
  const [filters, setFilters] = useState(filterData);
  const [searchParams, setSearchParams] = useSearchParams();
  const navigate = useNavigate();

  const searchProperties = (filterValues) => {
    const path = location.pathname;
    console.log(path);
    const query = searchParams.get("query");
    console.log(query); // undefined

    const values = getFilterValues(filterValues); // error
    // console.log(values);
    values.forEach((item) => {
      setSearchParams[item.name] = item.value;
    });

    navigate({ pathname: path, query });
  };

  return (
    <div className={classes.item}>
      {filters.map((filter) => (
        <DropDown
          key={filter.queryName}
          placeholder={filter.placeholder}
          filter={filter}
          onChange={(e) => {
            searchProperties({ [filter.queryName]: e.target.value });
          }}
        />
      ))}
    </div>
  );
};

export default FilterProperties;
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It seems you are misusing the setSearchParams function. The useSearchParams hook returns a URLSearchParams object and a setSearchParams function that works similarly to the navigate function but only updates the search part of the URL. The basic gist is that you only need to iterate over the filter key-value pairs, update the searchParams object, and then issue the imperative navigation with the updated query parameters.

Example:

...
const [searchParams, setSearchParams] = useSearchParams();
...

const searchProperties = (filterValues) => {
  const values = getFilterValues(filterValues); // *

  values.forEach(({ name, value }) => {
    searchParams.set(name, value); // <-- set query parameter value
  });

  setSearchParams(searchParams); // <-- update query params
};

* Note: I am assuming that getFilterValues(filterValues) functions and returns all the filter key-value pairs the UI is working with.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!