Skip to content

Commit

Permalink
fix: fixed potential error when hook suspends and error is accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeyper committed Jan 24, 2021
1 parent 3b45b4d commit 1a0c4d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/index.ts
Expand Up @@ -19,7 +19,7 @@ function resultContainer<TValue>() {
return value as TValue
},
get error() {
const { error } = results[results.length - 1]
const { error } = results[results.length - 1] ?? {}
return error
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/dom/__tests__/suspenseHook.test.ts
Expand Up @@ -52,4 +52,10 @@ describe('suspense hook tests', () => {

expect(result.current).toBe(undefined)
})

test('should return undefined if error is requested before suspension has resolved', async () => {
const { result } = renderHook(() => useFetchName(true))

expect(result.error).toBe(undefined)
})
})
6 changes: 6 additions & 0 deletions src/native/__tests__/suspenseHook.test.ts
Expand Up @@ -52,4 +52,10 @@ describe('suspense hook tests', () => {

expect(result.current).toBe(undefined)
})

test('should return undefined if error is requested before suspension has resolved', async () => {
const { result } = renderHook(() => useFetchName(true))

expect(result.error).toBe(undefined)
})
})

0 comments on commit 1a0c4d3

Please sign in to comment.