diff --git a/src/use-swrv.ts b/src/use-swrv.ts index 9c66493..e549caa 100644 --- a/src/use-swrv.ts +++ b/src/use-swrv.ts @@ -384,6 +384,7 @@ function useSWRV (...args): IResponse { watch(keyRef, (val) => { keyRef.value = val stateRef.key = val + stateRef.isValidating = Boolean(val) setRefCache(keyRef.value, stateRef, ttl) if (!IS_SERVER && !isHydrated && keyRef.value) { diff --git a/tests/use-swrv.spec.tsx b/tests/use-swrv.spec.tsx index e06b7ca..d412e24 100644 --- a/tests/use-swrv.spec.tsx +++ b/tests/use-swrv.spec.tsx @@ -683,6 +683,19 @@ describe('useSWRV - loading', () => { done() }) + + // #195 + it('should return loading state isValidating with nullish key', async done => { + const vm = new Vue(defineComponent({ + template: `
{{ error }}:{{this.isValidating ? 'loading' : 'ready'}}
`, + setup () { + return useSWRV(() => null) + } + })).$mount() + + expect(vm.$el.textContent).toBe(':ready') + done() + }) }) describe('useSWRV - mutate', () => {