Skip to content

Commit

Permalink
fix: do not start with loading true: check if on revalidating
Browse files Browse the repository at this point in the history
  • Loading branch information
cicerchia committed Aug 21, 2021
1 parent 5133e15 commit bfb36fb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface SWRStore<T> {
const defaultSWRStore = {
data: undefined,
error: undefined,
isLoading: true,
isLoading: false,
isFetching: false,
};

Expand Down Expand Up @@ -62,7 +62,11 @@ const swrMachine: FSMMachineConfig = {
ctx = { ...ctx, isLoading: false, data };
}
}
return { ...ctx, isFetching: true };
return {
...ctx,
isLoading: !(ctx.data || ctx.error),
isFetching: true,
};
},
on: {
revalidate: null,
Expand Down

0 comments on commit bfb36fb

Please sign in to comment.