Skip to content

Commit

Permalink
馃Ξ fix: isLoading form state (#10095)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Towle <atowle@ldms.com>
  • Loading branch information
adamtowle and Adam Towle committed Mar 13, 2023
1 parent 236dd6b commit a68f683
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/__tests__/useForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,14 @@ describe('useForm', () => {
});
});

it('should not update isLoading when literal defaultValues are provided', async () => {
const { result } = renderHook(() =>
useForm({ defaultValues: { test: 'default' } }),
);

expect(result.current.formState.isLoading).toBe(false);
});

it('should update isValidating to true when using with resolver', async () => {
jest.useFakeTimers();

Expand Down
2 changes: 1 addition & 1 deletion src/logic/createFormControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function createFormControl<
let _formState: FormState<TFieldValues> = {
submitCount: 0,
isDirty: false,
isLoading: true,
isLoading: isFunction(_options.defaultValues),
isValidating: false,
isSubmitted: false,
isSubmitting: false,
Expand Down
2 changes: 1 addition & 1 deletion src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function useForm<
const [formState, updateFormState] = React.useState<FormState<TFieldValues>>({
isDirty: false,
isValidating: false,
isLoading: true,
isLoading: isFunction(props.defaultValues),
isSubmitted: false,
isSubmitting: false,
isSubmitSuccessful: false,
Expand Down

0 comments on commit a68f683

Please sign in to comment.