Coder Social home page Coder Social logo

Comments (3)

simoneb avatar simoneb commented on July 21, 2024 1

I see what you mean. Yes it would make sense to have something like this, but because it would be quite some additional complexity to add to the package, which at the current time is overall quite simple, and because the workaround in your case is super simple as well, I wouldn't consider this a priority. I mean it's complexity added to the package versus a one line of code on the package user.

from axios-hooks.

simoneb avatar simoneb commented on July 21, 2024

Isn't this case already covered by the normal behavior of the hook together with the second item of the array returned by the hook invocation (sometimes called refetch) which allows you to issue the request again?

from axios-hooks.

stevewillard avatar stevewillard commented on July 21, 2024

Yeah, I think that would work, but I was hoping to avoid explicitly recalling refetch.

Here's the scenario I'm working with:

I have a table of data with pagination controls, where the page is stored in the URL as a query parameter. I'm using this hook to parse/set that query parameter: https://github.com/pbeshai/use-query-params

So, I have something like this:

const [page = 1, setPage] = useQueryParam('page', NumberParam);

const [{ data, loading, error }, refetch] = useAxios({
    url: 'my_api_route',
    params: {
        page,
    },
});

When I click on a new page, I call setPage which updates the URL, which re-renders the component and the axios hook will fetch the new page of data.

If I navigate back to a page I have already seen, axios-hooks will read from the cache, but what I want is to read from the cache and also issue a network request. I could definitely achieve this by calling refetch as part of the onClick for the pagination control which calls setPage, but I was hoping to do this automatically. The issue with this is that it'll issue two API calls the first time a page is loaded (once for when the component re-renders with the new page, and the refetch call will trigger it again).

from axios-hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.