Giter VIP home page Giter VIP logo

Comments (8)

simoneb avatar simoneb commented on June 12, 2024 1

Meanwhile, I went ahead and added tests by building on top of your PR here: #37.

I'm still not sure exactly what value this provides though, I'd like to hear your thoughts based on the previous comment.

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024 1

Thanks for confirming @verekia. Note that this is already possible by using the manual option and the execute function that is returned by the hook. For instance, in your component, you could easily do:

const [{ data }, execute] = useAxios(..., { manual: true })

useEffect(() => {
  execute()
}, [])

You would achieve the same as with this new option we're discussing. I appreciate it's additional code you have to write though.

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024 1

released in version 1.4.0

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024

Hi, sorry for the delay. This requires more details. By disabling cache, what do you mean exactly?

At the current time the hook is executed whenever the configuration (url and other request options) change. It wouldn't make sense to re-execute the hook every time that the component renders. So I presume that what you're saying is, when the component is re-mounted, which would execute the hook, instead of using the cache, which is what happens by default, skip it and execute the request again. I'm not sure what kind of benefit this provides though, because usually you wouldn't use component (re)mounting to decide when to execute requests. Can you clarify your scenario?

from axios-hooks.

verekia avatar verekia commented on June 12, 2024

For a given URL and request options, APIs may not always return the same data. Data may evolve over time, and an application might require to always get the latest data. Unless I am mistaken it seems impossible to use the hook if for instance, we run it on a homepage that would call, let's say /get-latest-posts. When navigating back and forth between such homepage of the app and other pages, we would not get the most recent data on the home page but some cached data. Refetching would not be an elegant solution in such case, since we really want to make a new fresh call at each mount.

from axios-hooks.

verekia avatar verekia commented on June 12, 2024

When I use Apollo Client, I prefer to disable the cache completely with a network-only fetch policy, because it is more valuable in my use case to be 100% sure we always get the latest data, than saving some requests.

from axios-hooks.

verekia avatar verekia commented on June 12, 2024

Thank you. Well it's true that it would work, but for me one of the main added value of this kind of network hook is to not have to use useEffect, which just feels so heavy after having had the pleasure to write lightweight code with network hooks. Functional components code are getting quite big now with hooks, so even those extra 3 lines of code have a cost for the codebase maintenance. My 2 cents :)

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024

@verekia can you review #37 then please?

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.