-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: initial data #26
Comments
hey, thanks! wouldn't the |
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. |
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. |
Right, as in Thanks for your time! |
Yes precisely. Don't forget to handle errors too though. You're welcome! |
It's best to have initial state of the whole object instead of conditionally creating it. There are many examples which makes the This is the main reason I uninstalled the package. The package looks good but I'd rather omit those Regards, |
@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? |
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. |
@STotev can you share your approach so we can see what is the obvious way of doing things? |
Let's say you have a calculation(say filtering and sorting results) which you want to memoize using P.S. If you expect code, I can make an example tonight. |
yes that would be very useful, thanks! |
I love this library, thanks for sharing!
One thing that I think would be very helpful is if the
useAxios
hook accepted an option for initial data with which to populate the request.For example, let's say I have a request that returns an array of objects, from which I am generating a table. I currently need to do something like:
It would be nice if I could do something like
const [req] = useAxios('...', { initialData: [] })
in the example above so that I don't have to handle the case wherereq.data
is undefined.If you like this idea, but not enough to bother implementing it yourself, let me know and I'll make time to send a PR.
Thanks!
The text was updated successfully, but these errors were encountered: