hyper-fetch icon indicating copy to clipboard operation
hyper-fetch copied to clipboard

Loading state does not reset when query parameters change in React useFetch

Open Toonba opened this issue 3 months ago • 1 comments

Hi,

I’m using HyperFetch (6.0.1) with React and useFetch for a paginated list.

I noticed that when I change the query parameters of a request (for example, switching pages), the loading state does not automatically go back to true, even though a new request is being triggered.

const [page, setPage] = useState(1);
const { data, loading } = useFetch(getPosts.setQueryParams({ page }); 

  const goToNextPage = () => {
    // Currently, I need to manually call:
    // setLoading(true);
    setPage((p) => p + 1);
  };

Currently, to show a loading indicator correctly, (for pages that haven’t been visited yet) I have to manually call setLoading(true) before changing queryParmas and triggering a new request

This works, but it feels like a workaround.

Question: Is there a built-in way for useFetch to automatically reset loading to true whenever query parameters change, so that the component reflects the new request’s loading state without manually managing it?

Note : I am currently using HyperFetch v6.0.1 and cannot upgrade to v7 yet due to this related issue

Thanks for your help!

Toonba avatar Sep 11 '25 11:09 Toonba

any info ?

lobor avatar Oct 03 '25 11:10 lobor