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 field #359

Open
vladnkolesnikov opened this issue Dec 1, 2023 · 4 comments
Open

isLoading field #359

vladnkolesnikov opened this issue Dec 1, 2023 · 4 comments

Comments

@vladnkolesnikov
Copy link

vladnkolesnikov commented Dec 1, 2023

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?

@adamdehaven
Copy link
Member

Could useSwrvState handle what you're needing?
https://docs-swrv.netlify.app/features.html#useswrvstate

@vladnkolesnikov
Copy link
Author

vladnkolesnikov commented Dec 1, 2023

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.

@vladnkolesnikov
Copy link
Author

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:

isValidating: true,

@adamdehaven
Copy link
Member

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.

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

No branches or pull requests

2 participants