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

154
Views
react-query dynamic number of parameters

I will have product filter on ecommerce page. I'm not sure how can I pass dynamic number of parameters in my query? Because sometimes will query use 1 parameter sometimes 6 and more.

Example

const fetchProducts = async (size, color, weight, deep,) => {
  const parsed = await ky(
    `http://localhost:3000/api/products/get?size=${size}&color=${color}`
  ).json();

  return parsed;
}; 


  const { data, status } = useQuery([size, color,], () => fetchPosts(size, color));

Sometimes will be 10 different parameters from the product filter, sometimes just 1...

How can I handle this dynamically? I will need then put the filter on prisma backend.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use qs package to handle all params.

Example:

const fetchProducts = (params)=>{
 const query = qs.stringify(params);
 const baseUrl = "http://localhost:3000/api/products/get?";
 const parsed = await ky(baseUrl + query);
....
}

const params = {color:"red", size:"big"}
const query = qs.stringify(params);
//output: "color=red&size=big"
about 4 years ago · Juan Pablo Isaza 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!