diff --git a/package.json b/package.json index b1d405b8..4abb6bf1 100644 --- a/package.json +++ b/package.json @@ -60,8 +60,8 @@ "@types/jest": "^29.2.5", "@types/lodash": "^4.14.135", "@types/node": "^22.0.2", - "@types/react": "^18.0.0", - "@types/react-dom": "^18.0.0", + "@types/react": "^19.0.6", + "@types/react-dom": "^19.0.1", "@umijs/fabric": "^4.0.1", "dumi": "^2.0.0", "eslint": "^8.54.0", diff --git a/src/Field.tsx b/src/Field.tsx index 73883031..69e680ce 100644 --- a/src/Field.tsx +++ b/src/Field.tsx @@ -543,9 +543,10 @@ class Field extends React.Component implements F } // Filed element only - const childList = toChildrenArray(children); + const childList = toChildrenArray(children as any); + if (childList.length !== 1 || !React.isValidElement(childList[0])) { - return { child: childList, isFunction: false }; + return { child: childList as React.ReactNode, isFunction: false }; } return { child: childList[0], isFunction: false }; diff --git a/src/Form.tsx b/src/Form.tsx index 24972de5..8c19210a 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -138,7 +138,7 @@ const Form: React.ForwardRefRenderFunction = ( useSubscribe(!childrenRenderProps); // Listen if fields provided. We use ref to save prev data here to avoid additional render - const prevFieldsRef = React.useRef(); + const prevFieldsRef = React.useRef(null); React.useEffect(() => { if (!isSimilar(prevFieldsRef.current || [], fields || [])) { formInstance.setFields(fields || []); diff --git a/src/useForm.ts b/src/useForm.ts index bb89d43b..fe8c8069 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -1027,7 +1027,7 @@ export class FormStore { } function useForm(form?: FormInstance): [FormInstance] { - const formRef = React.useRef(); + const formRef = React.useRef(null); const [, forceUpdate] = React.useState({}); if (!formRef.current) { diff --git a/tests/useWatch.test.tsx b/tests/useWatch.test.tsx index 0c08ab19..a52005db 100644 --- a/tests/useWatch.test.tsx +++ b/tests/useWatch.test.tsx @@ -288,9 +288,13 @@ describe('useWatch', () => { const more = Form.useWatch(['age', 'name', 'gender'], form); const demo = Form.useWatch(['demo']); - const values2 = Form.useWatch(values => ({ newName: values.name, newAge: values.age }), form); - const values3 = Form.useWatch(values => ({ - newName: values.name, + const values2 = Form.useWatch( + _values => ({ newName: _values.name, newAge: _values.age }), + form, + ); + + const values3 = Form.useWatch(_values => ({ + newName: _values.name, })); return ( @@ -393,7 +397,7 @@ describe('useWatch', () => { it('first undefined', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); const Demo: React.FC = () => { - const formRef = useRef(); + const formRef = useRef(null); const name = Form.useWatch('name', formRef.current); const [, setUpdate] = useState({}); return (