Skip to content

Commit

Permalink
fix: fix immediate option in userList (#378)
Browse files Browse the repository at this point in the history
* fix: fix immediate option in userList

* test: add test for useList

---------

Co-authored-by: jialan <jialan@dtstack.com>
  • Loading branch information
JackWang032 and jialan committed Sep 6, 2023
1 parent b4cdaf9 commit b8992f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/useList/__tests__/useList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ describe('Test useList hook', () => {

expect(fetcher).toBeCalledTimes(2);
});

it('Should support immediate option', () => {
const fetcher = jest.fn();

renderHook(() => useList(fetcher, {}, { immediate: false }));

expect(fetcher).not.toBeCalled();
});
});
2 changes: 1 addition & 1 deletion src/useList/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function useList<T extends Record<string, any>, P extends Record<
const [params, setParams] = useState<P>(initialParams);
const [loading, setLoading] = useState(false);

const options = useMemo(() => merge(rawOptions, { immediate: true }), [rawOptions]);
const options = useMemo(() => merge({ immediate: true }, rawOptions), [rawOptions]);

const performFetch = (raw = params) => {
setLoading(true);
Expand Down

0 comments on commit b8992f3

Please sign in to comment.