Skip to content

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

@Toonba

Description

@Toonba

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions