isLoading field
vladnkolesnikov opened this issue · comments
Hi,
there is a field isLoading
in the original library that allows to implement cases like initial state. Is there any plans to implement it soon?
Also I was curious if isValidating
field should be true
by default whenever key is missing?
Could useSwrvState
handle what you're needing?
https://docs-swrv.netlify.app/features.html#useswrvstate
Unfortunately not. I could if isValidating
was false
in case no key was provided, meaning the first request was skipped.
I have a case when I need to display several states:
- Initial state: request is not being called: data & error is
undefined
- loading state: data & error is undefined, waiting for response;
- success & error state;
- validating: has data, but new request is being called.
Also I was wondered why isValidating
state is true
by default? In original library initial value depends on few conditions like key
presence, initial params and so on
SWR implementation:
https://github.com/vercel/swr/blob/1d8110900d1aee3747199bfb377b149b7ff6848e/core/src/use-swr.ts#L302
Vue port implementation:
Line 230 in 649fc77
I have a case when I need to display several states:
- Initial state: request is not being called: data & error is
undefined
- loading state: data & error is undefined, waiting for response;
- success & error state;
- validating: has data, but new request is being called.
- The initial state would have to be known from your host app - if you're using dependent fetching or something to trigger the first fetch, the host app would obviously be in control of that state, so you should already know whether you have triggered the first fetch.