how to filter axios response? so i need to filter and get filtered response in browser, database is monodb...
const getNodeData = (route, params) =>
new Promise((resolve, reject) =>
axios.get(route, {
params,
withCredentials: true
})
.then((res) => reslove(get(res, 'data.data', [])))
.catch((error) =< reject(error))
);
CodePudding user response:
There are two ways for filtering yor response.
1 - If this filter will occour everytime, then you can need the query in the back end to adjust it.
2 - In the front end, get your response (res) and give a variable that uses a loop for filtering.
Example:
const getNodeData = (route, params) => {
axios.get(route, {
params,
withCredentials: true
})
.then((res) => {
const data = res.filter("YOUR FILTER CONDITION HERE")
return data;
})
.catch((error) => console.log(error))
}
