diff --git a/.gitignore b/.gitignore index b56b05fa..947964ae 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /yarn-error.log /yarn.lock /package-lock.json +pnpm-lock.yaml # production /dist @@ -29,4 +30,4 @@ .dumi/ package-lock.json -bun.lockb \ No newline at end of file +bun.lockb diff --git a/package.json b/package.json index a0b682d8..46f870a2 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ }, "dependencies": { "@rc-component/async-validator": "^5.0.3", - "@rc-component/util": "^1.1.0" + "@rc-component/util": "^1.3.0", + "clsx": "^2.1.1" }, "devDependencies": { "@rc-component/father-plugin": "^2.0.1", diff --git a/src/Form.tsx b/src/Form.tsx index 601d1c87..184cc2d5 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -14,7 +14,8 @@ import type { FormContextProps } from './FormContext'; import FormContext from './FormContext'; import { isSimilar } from './utils/valueUtil'; import ListContext from './ListContext'; -import BatchUpdate, { BatchTask, type BatchUpdateRef } from './BatchUpdate'; +import type { BatchTask, BatchUpdateRef } from './BatchUpdate'; +import BatchUpdate from './BatchUpdate'; type BaseFormProps = Omit, 'onSubmit' | 'children'>; @@ -185,7 +186,7 @@ const Form: React.ForwardRefRenderFunction = ( }, [fields, formInstance]); // =========================== Render =========================== - const formContextValue = React.useMemo( + const formContextValue = React.useMemo( () => ({ ...(formInstance as InternalFormInstance), validateTrigger, diff --git a/src/List.tsx b/src/List.tsx index 7bb22d01..b275555e 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -1,6 +1,13 @@ import * as React from 'react'; import warning from '@rc-component/util/lib/warning'; -import type { InternalNamePath, NamePath, StoreValue, ValidatorRule, Meta } from './interface'; +import type { + InternalNamePath, + NamePath, + StoreValue, + ValidatorRule, + Meta, + InternalFormInstance, +} from './interface'; import FieldContext from './FieldContext'; import Field from './Field'; import { move, getNamePath } from './utils/valueUtil'; @@ -40,18 +47,19 @@ function List({ }: ListProps) { const context = React.useContext(FieldContext); const wrapperListContext = React.useContext(ListContext); - const keyRef = React.useRef({ - keys: [], - id: 0, - }); + const keyRef = React.useRef({ keys: [], id: 0 }); + const keyManager = keyRef.current; - const prefixName: InternalNamePath = React.useMemo(() => { + const prefixName = React.useMemo(() => { const parentPrefixName = getNamePath(context.prefixName) || []; return [...parentPrefixName, ...getNamePath(name)]; }, [context.prefixName, name]); - const fieldContext = React.useMemo(() => ({ ...context, prefixName }), [context, prefixName]); + const fieldContext = React.useMemo( + () => ({ ...context, prefixName }), + [context, prefixName], + ); // List context const listContext = React.useMemo( @@ -62,7 +70,7 @@ function List({ return [keyManager.keys[pathName], namePath.slice(len + 1)]; }, }), - [prefixName], + [keyManager, prefixName], ); // User should not pass `children` as other type. diff --git a/src/useWatch.ts b/src/useWatch.ts index b3f93e83..74b10176 100644 --- a/src/useWatch.ts +++ b/src/useWatch.ts @@ -18,7 +18,7 @@ type GetGeneric = ReturnPromise { const watchValue = options.preserve - ? allValues ?? getFieldsValue(true) - : values ?? getFieldsValue(); + ? (allValues ?? getFieldsValue(true)) + : (values ?? getFieldsValue()); const nextValue = typeof dependencies === 'function' diff --git a/tests/common/InfoField.tsx b/tests/common/InfoField.tsx index e4faa52f..d110915c 100644 --- a/tests/common/InfoField.tsx +++ b/tests/common/InfoField.tsx @@ -17,18 +17,17 @@ const InfoField: React.FC = ({ children, ...props }) => ( {(control, info) => { const { errors, warnings, validating } = info; - return ( -
+
{children ? React.cloneElement(children, control) : }
    {errors.map((error, index) => ( -
  • {error}
  • +
  • {error}
  • ))}
    {warnings.map((warning, index) => ( -
  • {warning}
  • +
  • {warning}
  • ))}
{validating && }