ReactQuery fetch using search Params
Unanswered
Toyger posted this in #help-forum
ToygerOP
Hi, I'm fetching my backend API like :
On the same page, I possess a sidebar filter that alters the URL parameters based on the selected filters (e.g., server.com/trips?city=monaco&isGuided). Thus, I require a method to consistently retrieve the updated URL parameters whenever they are changed.
Thanks
const fetchTrips = async (page: number) => {
const {data} = await http.get(`${API_ENDPOINTS.TRIPS}?page=${page}&limit=${FETCH_LIMIT}`);
return {
data: data.trips,
total: data.total,
}
};
const useTripsQuery = () => {
return useInfiniteQuery("trips", ({ pageParam = 1 }) => fetchTrips(pageParam), {
getNextPageParam: (lastPage: any, allPages: any) => {
const nextPage = lastPage?.data?.length === FETCH_LIMIT ? allPages.length + 1 : undefined;
return nextPage;
}
});
}On the same page, I possess a sidebar filter that alters the URL parameters based on the selected filters (e.g., server.com/trips?city=monaco&isGuided). Thus, I require a method to consistently retrieve the updated URL parameters whenever they are changed.
Thanks