Skip to content

Commit c09513f

Browse files
authored
fix(useAntdHooks):fix autorequest with manual is true (#2714)
1 parent 0384682 commit c09513f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/hooks/src/useAntdTable/__tests__/index.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,37 @@ describe('useAntdTable', () => {
347347
expect(queryArgs.pageSize).toBe(100);
348348
});
349349
});
350+
351+
it("should defaultParams work with manual is true", async () => {
352+
queryArgs = undefined;
353+
form.resetFields();
354+
changeSearchType("advance");
355+
356+
act(() => {
357+
renderHook((o) => {
358+
const [myForm] = Form.useForm();
359+
360+
useAntdTable(
361+
asyncFn,
362+
o || {
363+
form: myForm,
364+
defaultParams: [
365+
{
366+
current: 2,
367+
pageSize: 10,
368+
},
369+
{ name: "hello", phone: "123" },
370+
],
371+
defaultType: "advance",
372+
}
373+
);
374+
375+
useEffect(() => {
376+
// defaultParams works
377+
expect(myForm.getFieldValue("name")).toBe("hello");
378+
expect(queryArgs).toBe(undefined);
379+
}, []);
380+
});
381+
});
382+
});
350383
});

packages/hooks/src/useAntdTable/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ const useAntdTable = <TData extends Data, TParams extends Params>(
211211
if (ready) {
212212
allFormDataRef.current = defaultParams?.[1] || {};
213213
restoreForm();
214-
_submit(defaultParams?.[0]);
214+
if (!manual) {
215+
_submit(defaultParams?.[0]);
216+
}
215217
}
216218
}, []);
217219

0 commit comments

Comments
 (0)