Skip to content

Commit 07996ea

Browse files
authored
feat: add warning "cannot be a function" in getValueProps (#642)
* feat: add warning "cannot be a function" in getValueProps * feat: when not production to warning & use not recommended * feat: 优化文案 * feat: add ` to getValueProps * feat: add ` to getValueProps
1 parent 75a5899 commit 07996ea

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Field.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export type MetaEvent = Meta & { destroy?: boolean };
5959

6060
export interface InternalFieldProps<Values = any> {
6161
children?:
62-
| React.ReactElement
63-
| ((control: ChildProps, meta: Meta, form: FormInstance<Values>) => React.ReactNode);
62+
| React.ReactElement
63+
| ((control: ChildProps, meta: Meta, form: FormInstance<Values>) => React.ReactNode);
6464
/**
6565
* Set up `dependencies` field.
6666
* When dependencies field update and current field is touched,
@@ -578,9 +578,18 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
578578
// eslint-disable-next-line @typescript-eslint/no-explicit-any
579579
const originTriggerFunc: any = childProps[trigger];
580580

581+
const valueProps = mergedGetValueProps(value);
582+
583+
// warning when prop value is function
584+
if (process.env.NODE_ENV !== 'production') {
585+
Object.keys(valueProps).forEach(key => {
586+
warning(typeof valueProps[key] !== 'function', `It's not recommended to generate dynamic function prop by \`getValueProps\`. Please pass it to child component directly (prop: ${key})`)
587+
})
588+
}
589+
581590
const control = {
582591
...childProps,
583-
...mergedGetValueProps(value),
592+
...valueProps,
584593
};
585594

586595
// Add trigger

0 commit comments

Comments
 (0)