Coder Social home page Coder Social logo

Comments (4)

CloudPower97 avatar CloudPower97 commented on June 22, 2024 1

Hey, @simoneb @captrespect, I was just reading the repo issues and stumbled upon this.
To me, it seems that the second request can be accomplished simply using default parameters.
For example:

const [
    { data = [{ userId: 1, title: "Default Parameter", completed: false }], loading, error },
    refetch
  ] = useAxios("https://jsonplaceholder.typicode.com/todos");

Until the new data get fetched from axios the default one will be shown.
This is not going to work while refetching, though.

from axios-hooks.

simoneb avatar simoneb commented on June 22, 2024

Ok let's keep them as 2 different issues:

  1. can you use an axios response transformer for this? https://github.com/axios/axios#request-config
  2. it's been asked before but the author didn't go as far as explaining how it would be beneficial. This wouldn't be a big change but I'm wondering if it's needed. Isn't the loading flag covering this already?

from axios-hooks.

captrespect avatar captrespect commented on June 22, 2024

The transformer for axios does look like a better place for that. Thanks!

I did try using the loading flag, but I think because the form renders before the call is even made I think was getting the undefined for the data, and false for loading. I'd have to check again.

Either way I was trying to get rid of the extra check before rendering. It wouldn't matter if it was the loading flag or checking fo the data:

loading && data.map(...)
data && data.map(...)

With a default I could just say:
data.map(...)

But in the end, it's probably a toss up between the complexity of adding another option vs just checking for data before rendering. It's probably not a bad idea to do the check anyway, incase of some other error.

I guess I just talked my way out of it.

Thanks again.

from axios-hooks.

simoneb avatar simoneb commented on June 22, 2024

@captrespect on point 2) you're right, an additional option would make it slightly easier but I think it's redundant with what you can already do with the loading flag. I realize that the code you'd have to write if we had this option would be slightly nicer, but I don't find the alternative to be so bad as to justify having an additional option

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.