Comments (11)
hey, thanks! wouldn't the loading
flag allow you to do this?
from axios-hooks.
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.
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.
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.
Yes precisely. Don't forget to handle errors too though. You're welcome!
from axios-hooks.
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.
@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.
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.
@STotev can you share your approach so we can see what is the obvious way of doing things?
from axios-hooks.
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.
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)
- Release pending!
- Refetch "expression is not callable" HOT 2
- Why I'm getting 2 rendered using this hook, when component mounts? HOT 9
- Release pending!
- Prevent CanceledError and redundant HTTP calls for identical request data HOT 1
- Support for API polling HOT 1
- type error HOT 9
- Uncaught TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator)) HOT 1
- How to configure SSR with NextJS? HOT 3
- "Uncaught runtime errors: Cannot read properties of undefined (reading 'data')" after upgrading to CRA 5.0.1 & Node 18 HOT 6
- Not usable within the US? HOT 1
- Error from a dynamically loaded uri HOT 3
- Release pending!
- Release pending!
- useAxios hook sending in 2 requests, the first is cancelled immediately HOT 3
- Release pending! HOT 3
- Release pending!
- Release pending!
- Type error: MouseEvent using refetch and provided example from docs HOT 2
- Still an issue with both `executeGet` and `execute` methods when executed manually HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios-hooks.