Skip to content
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

isLoading only works on the first fetch (solution in comments) #193

Closed
3 tasks done
mikiekwoods opened this issue Feb 7, 2022 · 7 comments
Closed
3 tasks done

isLoading only works on the first fetch (solution in comments) #193

mikiekwoods opened this issue Feb 7, 2022 · 7 comments
Labels
question Further information is requested

Comments

@mikiekwoods
Copy link

mikiekwoods commented Feb 7, 2022

New Bug Report

Checklist

Issue Description

Steps + code to reproduce

Actual Outcome

isLoading only can be true on first fetch.

Expected Outcome

isLoading should be true on every fetch where the data is empty...including empty array

Someone else posted this in Novemeber, and I ran into the issue myself:
https://forum.moralis.io/t/bug-in-isloading-when-using-usemoraliscloudfunction-in-react/4453

I HAVE PLACED A SOLUTION IN MY THREAD!
https://forum.moralis.io/t/isloading-is-always-false-on-usemoralisquery/9549

The isLoading state conditional statement needs to allow the empty array possibility, where as now it only can be true if data is null.

I didn't have time to test enough to put in a pull request.

@ErnoW
Copy link
Member

ErnoW commented Feb 9, 2022

You can use isFetching for those use-cases?
isLoading will indicate when you have no data and are fetching for data
isFetching will indicate every time when you're fetching for data

Does this help? Or otherwise I might misunderstand you.

@ErnoW ErnoW added the question Further information is requested label Feb 9, 2022
@mikiekwoods
Copy link
Author

The problem with fetch is that it happens every single time you load data. For example, if have a list, I might want to show a loadbar or skeleton the first time it loads. But then when it gets updated, I don't need to hide what I loaded. But sometimes the first load is an empty array, in which case isLoading should be true again.

But either way the way it is coded now is wrong.

const isLoading = isFetching && data == null && (Array.isArray(data) ? data.length === 0 : true); //This line can never cause the statement to be true.

@mikiekwoods
Copy link
Author

What I mean is this line will never cause it to be true
(Array.isArray(data) ? data.length === 0 : true);
Because if it is an array, this will always be false
data == null

@mikiekwoods
Copy link
Author

In other words, if you don't agree with my use case, you should get rid of this line
(Array.isArray(data) ? data.length === 0 : true);

@ErnoW
Copy link
Member

ErnoW commented Feb 9, 2022

Ah, thanks for clarifying, I see now what you mean.
It should check for "emptynesss", so should be a null check OR an empty array check.
Will fix it

@ErnoW
Copy link
Member

ErnoW commented Feb 9, 2022

Fixed in #200

@ErnoW ErnoW closed this as completed Mar 21, 2022
@ErnoW
Copy link
Member

ErnoW commented Mar 21, 2022

Released in 1.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants