Skip to content
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
14 changes: 9 additions & 5 deletions src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ export class FormStore {
};

private warningUnhooked = () => {
if (process.env.NODE_ENV !== 'production' && !this.formHooked) {
warning(
false,
'Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?',
);
if (process.env.NODE_ENV !== 'production') {
setTimeout(() => {
if (!this.formHooked) {
warning(
false,
'Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?',
);
}
});
}
};

Expand Down
3 changes: 3 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ describe('Form.Basic', () => {
});

it('warning if call function before set prop', () => {
jest.useFakeTimers();
resetWarned();
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

Expand All @@ -529,10 +530,12 @@ describe('Form.Basic', () => {

mount(<Test />);

jest.runAllTimers();
expect(errorSpy).toHaveBeenCalledWith(
'Warning: Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?',
);
errorSpy.mockRestore();
jest.useRealTimers();
});

it('filtering fields by meta', async () => {
Expand Down