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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/yarn-error.log
/yarn.lock
/package-lock.json
pnpm-lock.yaml

# production
/dist
Expand All @@ -29,4 +30,4 @@
.dumi/
package-lock.json

bun.lockb
bun.lockb
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'children'>;

Expand Down Expand Up @@ -185,7 +186,7 @@ const Form: React.ForwardRefRenderFunction<FormRef, FormProps> = (
}, [fields, formInstance]);

// =========================== Render ===========================
const formContextValue = React.useMemo(
const formContextValue = React.useMemo<InternalFormInstance>(
() => ({
...(formInstance as InternalFormInstance),
validateTrigger,
Expand Down
24 changes: 16 additions & 8 deletions src/List.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -40,18 +47,19 @@ function List<Values = any>({
}: ListProps<Values>) {
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<InternalNamePath>(() => {
const parentPrefixName = getNamePath(context.prefixName) || [];
return [...parentPrefixName, ...getNamePath(name)];
}, [context.prefixName, name]);

const fieldContext = React.useMemo(() => ({ ...context, prefixName }), [context, prefixName]);
const fieldContext = React.useMemo<InternalFormInstance>(
() => ({ ...context, prefixName }),
[context, prefixName],
);

// List context
const listContext = React.useMemo<ListContextProps>(
Expand All @@ -62,7 +70,7 @@ function List<Values = any>({
return [keyManager.keys[pathName], namePath.slice(len + 1)];
},
}),
[prefixName],
[keyManager, prefixName],
);

// User should not pass `children` as other type.
Expand Down
6 changes: 3 additions & 3 deletions src/useWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type GetGeneric<TForm extends FormInstance> = ReturnPromise<ReturnType<TForm['va
export function stringify(value: any) {
try {
return JSON.stringify(value);
} catch (err) {
} catch {
return Math.random();
}
}
Expand Down Expand Up @@ -119,8 +119,8 @@ function useWatch(
// ============================= Update =============================
const triggerUpdate = useEvent((values?: any, allValues?: any) => {
const watchValue = options.preserve
? allValues ?? getFieldsValue(true)
: values ?? getFieldsValue();
? (allValues ?? getFieldsValue(true))
: (values ?? getFieldsValue());

const nextValue =
typeof dependencies === 'function'
Expand Down
7 changes: 3 additions & 4 deletions tests/common/InfoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ const InfoField: React.FC<InfoFieldProps> = ({ children, ...props }) => (
<Field {...props}>
{(control, info) => {
const { errors, warnings, validating } = info;

return (
<div className='field'>
<div className="field">
{children ? React.cloneElement(children, control) : <Input {...control} />}
<ul className="errors">
{errors.map((error, index) => (
<li key={index}>{error}</li>
<li key={`error-${index}`}>{error}</li>
))}
</ul>
<ul className="warnings">
{warnings.map((warning, index) => (
<li key={index}>{warning}</li>
<li key={`warning-${index}`}>{warning}</li>
))}
</ul>
{validating && <span className="validating" />}
Expand Down