Skip to content

Commit 245d2eb

Browse files
refactor: fix types
1 parent e282e45 commit 245d2eb

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

packages/ra-core/src/form/FormDataConsumer.tsx

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import * as React from 'react';
22
import { ReactNode } from 'react';
3-
import {
4-
useWatch,
5-
useFormContext,
6-
FieldValues,
7-
PathValue,
8-
Path,
9-
} from 'react-hook-form';
3+
import { useWatch, useFormContext, FieldValues } from 'react-hook-form';
104
import get from 'lodash/get';
115

126
/**
@@ -50,13 +44,13 @@ import get from 'lodash/get';
5044
const FormDataConsumer = <TFieldValues extends FieldValues = FieldValues>(
5145
props: ConnectedProps<TFieldValues>
5246
) => {
53-
const { getValues } = useFormContext();
54-
const formData = useWatch<TFieldValues>();
47+
const { getValues } = useFormContext<TFieldValues>();
48+
let formData = (useWatch<TFieldValues>() as unknown) as TFieldValues;
5549

5650
//useWatch will initially return the provided defaultValues of the form.
5751
//We must get the initial formData from getValues
5852
if (Object.keys(formData).length === 0) {
59-
(formData as FieldValues) = getValues();
53+
formData = getValues();
6054
}
6155

6256
return (
@@ -65,10 +59,9 @@ const FormDataConsumer = <TFieldValues extends FieldValues = FieldValues>(
6559
};
6660

6761
export const FormDataConsumerView = <
68-
TFieldValues extends FieldValues = FieldValues,
69-
TPathValue = PathValue<TFieldValues, Path<TFieldValues>>[]
62+
TFieldValues extends FieldValues = FieldValues
7063
>(
71-
props: Props<TPathValue>
64+
props: Props<TFieldValues>
7265
) => {
7366
const { children, form, formData, source, index, ...rest } = props;
7467
let ret;

0 commit comments

Comments
 (0)