This is the custom hook
export const useFilteredProfiles = (filters) => {
const { type, state, occupancy, propertyValue, loanToValue } = filters
return useQuery({
queryKey: ['profiles', type, state, occupancy, propertyValue, loanToValue]
, queryFn: ({ queryKey }) => fetchData(queryKey),
refetchOnWindowFocus: false,
retry: false,
staleTime: Infinity,
enabled: !!type
});
}
which I used in two components on separate pages
There are filters on first page using these filter state I use above hook to fetch and show count of profiles present.
There is button in first page onClick I pass these filter states in router query (as show in below code)
To use filter state in another page to get cached profiles data, but it makes api request there instead of getting it from cache.
const handleClick = () => {
router.push({ pathname: `${router.pathname}/profiles`, query: { type, state, occupancy, propertyValue, loanToValue } });
}
Am I doing something wrong?