Closed mikiekwoods closed 2 years ago
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.
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.
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
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);
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
Released in 1.3.1
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.