0

Let's say I have a filter data gender array and a sort variable

const gender= ["male","Female"]
// consider this as a dynamic array it can be null or male or female or both male and female

const[sort,setSort]=useState("rec")  
//sort will be either rec or asc or desc

const changeGender = ()=>{
Setsearchparams({"gender":gender})
}

const changeSort = ()=>{
Setsearchparams({"sort":sort})
}

Now, if the user clicks on the gender filter the query string should be ?gender=male

if user clicks on the sort, the query string should be ?sort=rec

if the user clicks on the sort after gender filter the query string should be ?gender=male&sort=rec or if gender array has two elements it will then look like ?gender=male,female&sort=rec

and vice versa ?sort=rec&gender=male

How can I achieve such thing so that can I add multiple filters

Arman Kazi
  • 159
  • 1
  • 8
  • you can check this answer : https://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript – Ji aSH Sep 03 '22 at 11:29

0 Answers0