Giter VIP home page Giter VIP logo

Comments (2)

simoneb avatar simoneb commented on June 12, 2024 1

There's an improvement you can do over this, but it feels like a little overkill to use hooks for it.

See the sample I put together here.

It's pretending to do something similar to what you're trying to achieve by first retrieving a list of todos and then requesting the details of the first of them, by its id property.

Basically, you create two manual requests and you use the Promise returned by invoking the refetch function of the first to extract the response and provide it as input to the second.

There's one drawback to consider here, which is a by-product of how the hook works. In your case you probably wouldn't want to cause the component to re-render after the first request completes and wait to get the response from the second instead. There is currently no way to achieve that with this library, because whenever any request triggered using the Hook gets a response, the component will re-render.
It may not be a big deal, but something to be aware of. For a scenario like this, I would consider not using the Hook in the first place.

from axios-hooks.

wulucxy avatar wulucxy commented on June 12, 2024

@simoneb got it,thanks for your comment。

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.