Giter VIP home page Giter VIP logo

Comments (11)

simoneb avatar simoneb commented on June 3, 2024

hey, thanks! wouldn't the loading flag allow you to do this?

from axios-hooks.

malexdev avatar malexdev commented on June 3, 2024

loading definitely also solves this issue, yes.

I was thinking for interfaces where the loading flag isn't really necessary to use - for example a table of data that almost always populates "instantly" doesn't necessarily need to show a loading indicator, so having an initial data set could make it a little simpler instead of having to conditionally render an empty table based on the loading flag.

But I do agree, the issue is quite minor.

from axios-hooks.

simoneb avatar simoneb commented on June 3, 2024

You don't have to conditionally render, you can simply use the loading flag as the conditional to provide either empty data to the table or the data coming from the response.

from axios-hooks.

malexdev avatar malexdev commented on June 3, 2024

Right, as in (req.loading ? [] : req.data).map(...), which is almost the same as my initial example.
I agree, it's definitely a very minor thing. I'll just keep going as I am then.

Thanks for your time!

from axios-hooks.

simoneb avatar simoneb commented on June 3, 2024

Yes precisely. Don't forget to handle errors too though. You're welcome!

from axios-hooks.

STotev avatar STotev commented on June 3, 2024

It's best to have initial state of the whole object instead of conditionally creating it.

There are many examples which makes the loading check a little bit inconvenient. If you are waiting for an array response and you do calculations with the expected data, it'll fail until you get a response. It'll be very inconvenient of always checking the loading state before using the data. If you make calculations in multiple places (different phases of the app), declaring an initial empty array, for example, would be helpful because the app will still be running without any extra checks which in this case are redundant.

This is the main reason I uninstalled the package. The package looks good but I'd rather omit those loading checks and write a custom hook myself.
Probably many people will do the same because of the same reason.

Regards,
Stefan

from axios-hooks.

simoneb avatar simoneb commented on June 3, 2024

@STotev What this package is doing is the same as pretty much all other Hooks libraries that allow you to interact with an external service do. Can you share an example of the loading flag making the code so much harder to write?

from axios-hooks.

STotev avatar STotev commented on June 3, 2024

It's not about "so much harder". It's about cleanliness and redundancy. I am not here to have an argument with anyone. I am not the author, it's your decision what to do. I am just pointing the obvious.

from axios-hooks.

simoneb avatar simoneb commented on June 3, 2024

@STotev can you share your approach so we can see what is the obvious way of doing things?

from axios-hooks.

STotev avatar STotev commented on June 3, 2024

Let's say you have a calculation(say filtering and sorting results) which you want to memoize using useMemo(). Every time you change the data(updating a record or removing it) you need to trigger useMemo() again so to recalculate the changed data.
Without having data as a dependency on useMemo() I can't use the recalculation. In this case loading doesn't help because it's going to change on REQUEST_START and then REQUEST_END which will trigger useMemo() twice which is unwanted.

P.S. If you expect code, I can make an example tonight.

from axios-hooks.

simoneb avatar simoneb commented on June 3, 2024

P.S. If you expect code, I can make an example tonight.

yes that would be very useful, thanks!

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.