Skip to content

Commit 347e539

Browse files
authored
fix(use-dataloader): avoid exception when options are not defined (#148)
* fix(use-dataloader): avoid exception when options are not defined * test: add bug reproduction
1 parent b84d555 commit 347e539

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/use-dataloader/src/__tests__/useDataLoader.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ const wrapper = ({ children }) => (
2020
)
2121

2222
describe('useDataLoader', () => {
23+
test('should render correctly without options', async () => {
24+
const { result, waitForNextUpdate, rerender } = renderHook(
25+
props => useDataLoader(props.key, props.method),
26+
{
27+
wrapper,
28+
initialProps,
29+
},
30+
)
31+
expect(result.current.data).toBe(undefined)
32+
expect(result.current.isLoading).toBe(true)
33+
rerender()
34+
await waitForNextUpdate()
35+
expect(result.current.data).toBe(true)
36+
expect(result.current.isSuccess).toBe(true)
37+
expect(result.current.isLoading).toBe(false)
38+
})
39+
2340
test('should render correctly with enabled true', async () => {
2441
const { result, waitForNextUpdate, rerender } = renderHook(
2542
props => useDataLoader(props.key, props.method, props.config),

packages/use-dataloader/src/useDataLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const useDataLoader = (
2222
enabled = true,
2323
reloadOnKeyChange = true,
2424
keepPreviousData = true,
25-
},
25+
} = {},
2626
) => {
2727
const {
2828
addCachedData,

0 commit comments

Comments
 (0)