This is my simle React Query function for useQuery
var { isPending, isError, data } = useQuery({
queryKey: ['ordersFetch'],
queryFn: () => fetch(FETCH_ORDERS_API + pageNumber.order).then((res) => res.json())
})
I am changing the pageNumber.order by using the contextApi which results in URL change, but it is not refetching the data, how can i fetch data whenever my url changes here ?
On one screen I change the pageNumber state and then navigate to the different screen at that moment useQuery refetches the data but not when i change the state and remains on the same screen
2
Answers
Try to use use location hooks from react-router-dom to refetch the data when URL is changed.