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

fix(isValidating): add nullish check when no key #205

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/use-swrv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,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 @@ -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: `<div>{{ error }}:{{this.isValidating ? 'loading' : 'ready'}}</div>`,
setup () {
return useSWRV(() => null)
}
})).$mount()

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

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