Skip to content

Commit

Permalink
fix(isValidating): add nullish check when no key (#205)
Browse files Browse the repository at this point in the history
Fixes #195
  • Loading branch information
darrenjennings committed Mar 12, 2022
1 parent 314d8a1 commit 4e97a16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/use-swrv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ function useSWRV<Data = any, Error = any> (...args): IResponse<Data, Error> {
watch(keyRef, (val) => {
keyRef.value = val
stateRef.key = val
stateRef.isValidating = Boolean(val)
setRefCache(keyRef.value, stateRef, ttl)

if (!IS_SERVER && !isHydrated && keyRef.value) {
Expand Down
13 changes: 13 additions & 0 deletions tests/use-swrv.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,19 @@ describe('useSWRV - loading', () => {
expect(wrapper.text()).toBe('hello, data, ready')
done()
})

// #195
it('should return loading state isValidating with nullish key', async done => {
const vm = new Vue(defineComponent({
template: `<div>{{ error }}:{{this.isValidating ? 'loading' : 'ready'}}</div>`,
setup () {
return useSWRV(() => null)
}
})).$mount()

expect(vm.$el.textContent).toBe(':ready')
done()
})
})

describe('useSWRV - mutate', () => {
Expand Down

0 comments on commit 4e97a16

Please sign in to comment.