isLoading is initially false
dohomi opened this issue · 4 comments
Hello,
I just tried out your lib. In use with useFetch
, would it not be better to set isLoading
initially to true
? Otherwise the component initially would render as its not loading and a wrong component/logic could run.
Just an idea while testing this hook
Cheers
Hey, @dohomi!
I think at most cases data
exist check more useful that isLoading
check. Also, we can use them both.
As en example,
const Component = () => {
const { isLoading, data } = useFetch("...");
if (!data || isLoading) {
return <Spinner />
}
return <SomeOtherComponent {...data} />
};
What are you think about? Maybe it will fit your cases.
@ilyalesik this is how I solve it now. I just thought there might be a usecase where data would be null|undefined|0
from the async call and then the Spinner would run forever.
For me its fine how it is now, I just thought the isLoading hook should initially always be true because the hook will always run initially. Then the data
would not be needed to be called to check a loading spinner
It sounds reasonable. I did isLoading=true by default since version v1.7.0
.
thanks 👍