Skip to content

Commit 7807a40

Browse files
authored
perf: uninstall classnames, install clsx (#763)
1 parent 64356cd commit 7807a40

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/yarn-error.log
77
/yarn.lock
88
/package-lock.json
9+
pnpm-lock.yaml
910

1011
# production
1112
/dist
@@ -29,4 +30,4 @@
2930
.dumi/
3031
package-lock.json
3132

32-
bun.lockb
33+
bun.lockb

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
},
5151
"dependencies": {
5252
"@rc-component/async-validator": "^5.0.3",
53-
"@rc-component/util": "^1.1.0"
53+
"@rc-component/util": "^1.3.0",
54+
"clsx": "^2.1.1"
5455
},
5556
"devDependencies": {
5657
"@rc-component/father-plugin": "^2.0.1",

src/Form.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import type { FormContextProps } from './FormContext';
1414
import FormContext from './FormContext';
1515
import { isSimilar } from './utils/valueUtil';
1616
import ListContext from './ListContext';
17-
import BatchUpdate, { BatchTask, type BatchUpdateRef } from './BatchUpdate';
17+
import type { BatchTask, BatchUpdateRef } from './BatchUpdate';
18+
import BatchUpdate from './BatchUpdate';
1819

1920
type BaseFormProps = Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'children'>;
2021

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

187188
// =========================== Render ===========================
188-
const formContextValue = React.useMemo(
189+
const formContextValue = React.useMemo<InternalFormInstance>(
189190
() => ({
190191
...(formInstance as InternalFormInstance),
191192
validateTrigger,

src/List.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import * as React from 'react';
22
import warning from '@rc-component/util/lib/warning';
3-
import type { InternalNamePath, NamePath, StoreValue, ValidatorRule, Meta } from './interface';
3+
import type {
4+
InternalNamePath,
5+
NamePath,
6+
StoreValue,
7+
ValidatorRule,
8+
Meta,
9+
InternalFormInstance,
10+
} from './interface';
411
import FieldContext from './FieldContext';
512
import Field from './Field';
613
import { move, getNamePath } from './utils/valueUtil';
@@ -40,18 +47,19 @@ function List<Values = any>({
4047
}: ListProps<Values>) {
4148
const context = React.useContext(FieldContext);
4249
const wrapperListContext = React.useContext(ListContext);
43-
const keyRef = React.useRef({
44-
keys: [],
45-
id: 0,
46-
});
50+
const keyRef = React.useRef({ keys: [], id: 0 });
51+
4752
const keyManager = keyRef.current;
4853

49-
const prefixName: InternalNamePath = React.useMemo(() => {
54+
const prefixName = React.useMemo<InternalNamePath>(() => {
5055
const parentPrefixName = getNamePath(context.prefixName) || [];
5156
return [...parentPrefixName, ...getNamePath(name)];
5257
}, [context.prefixName, name]);
5358

54-
const fieldContext = React.useMemo(() => ({ ...context, prefixName }), [context, prefixName]);
59+
const fieldContext = React.useMemo<InternalFormInstance>(
60+
() => ({ ...context, prefixName }),
61+
[context, prefixName],
62+
);
5563

5664
// List context
5765
const listContext = React.useMemo<ListContextProps>(
@@ -62,7 +70,7 @@ function List<Values = any>({
6270
return [keyManager.keys[pathName], namePath.slice(len + 1)];
6371
},
6472
}),
65-
[prefixName],
73+
[keyManager, prefixName],
6674
);
6775

6876
// User should not pass `children` as other type.

src/useWatch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type GetGeneric<TForm extends FormInstance> = ReturnPromise<ReturnType<TForm['va
1818
export function stringify(value: any) {
1919
try {
2020
return JSON.stringify(value);
21-
} catch (err) {
21+
} catch {
2222
return Math.random();
2323
}
2424
}
@@ -119,8 +119,8 @@ function useWatch(
119119
// ============================= Update =============================
120120
const triggerUpdate = useEvent((values?: any, allValues?: any) => {
121121
const watchValue = options.preserve
122-
? allValues ?? getFieldsValue(true)
123-
: values ?? getFieldsValue();
122+
? (allValues ?? getFieldsValue(true))
123+
: (values ?? getFieldsValue());
124124

125125
const nextValue =
126126
typeof dependencies === 'function'

tests/common/InfoField.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ const InfoField: React.FC<InfoFieldProps> = ({ children, ...props }) => (
1717
<Field {...props}>
1818
{(control, info) => {
1919
const { errors, warnings, validating } = info;
20-
2120
return (
22-
<div className='field'>
21+
<div className="field">
2322
{children ? React.cloneElement(children, control) : <Input {...control} />}
2423
<ul className="errors">
2524
{errors.map((error, index) => (
26-
<li key={index}>{error}</li>
25+
<li key={`error-${index}`}>{error}</li>
2726
))}
2827
</ul>
2928
<ul className="warnings">
3029
{warnings.map((warning, index) => (
31-
<li key={index}>{warning}</li>
30+
<li key={`warning-${index}`}>{warning}</li>
3231
))}
3332
</ul>
3433
{validating && <span className="validating" />}

0 commit comments

Comments
 (0)