DEV Community

Kunal Singhdeo
Kunal Singhdeo

Posted on

How to do api search based on multiple input fields in react?

I have around 4 input fields and am storing their inputted value as an array of object using onChange

//
const info = [{
template:"",
date:"",
status:"",
owner:"",
}]

const [data, setData] = useState(info)

const handleImputChange = () => {
setData(...data, //storing input data for any given field )
}

}

My question is how to pass any no of keys, value(from state Variable) into the api in order to get the desired filtered output

For Ex:
const response = axios.get("xyz.search?templateName = random")
for the given api will be using any axios or fetch to get the value, over here I've hard coded input field and the value for it, so it will search the DB with the provided key value pair.

Let's say how to pass mutiple key value pairs through the api?

Top comments (0)