You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this logic fails after the first render of the hook/component. On the first render data is undefined. Then response is completed, and data becomes a value to consume in the UI.
Let's say I change the id via the UI and want to show loading indicator. Because data is no longer undefined, the same logic fails.
There is an additional item returned isValidating. So I updated my logic:
So in theory something else causes my component to rerender. This could inadvertently cause a "revalidation" and trigger loading state gets shown. This could break the UI temporarily, by accident.
So how do you derive "loading" between URL changes without revalidation? I am trying to replicate how graphQL Apollo Client returns const { loading, error, data } = useQuery(GET_DOGS);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I was asked a question regarding SWRs "loading" state:
The docs make it appear straight forward:
However, this logic fails after the first render of the hook/component. On the first render data is
undefined
. Then response is completed, and data becomes a value to consume in the UI.Let's say I change the
id
via the UI and want to show loading indicator. Becausedata
is no longerundefined
, the same logic fails.There is an additional item returned
isValidating
. So I updated my logic:However, this could be true when:
So in theory something else causes my component to rerender. This could inadvertently cause a "revalidation" and trigger loading state gets shown. This could break the UI temporarily, by accident.
So how do you derive "loading" between URL changes without revalidation? I am trying to replicate how graphQL Apollo Client returns
const { loading, error, data } = useQuery(GET_DOGS);
Beta Was this translation helpful? Give feedback.
All reactions