diff --git a/src/Field.tsx b/src/Field.tsx index da79afdf..10c3ad3b 100644 --- a/src/Field.tsx +++ b/src/Field.tsx @@ -561,6 +561,7 @@ class Field extends React.Component implements F public getControlled = (childProps: ChildProps = {}) => { const { + name, trigger, validateTrigger, getValueFromEvent, @@ -582,7 +583,7 @@ class Field extends React.Component implements F // eslint-disable-next-line @typescript-eslint/no-explicit-any const originTriggerFunc: any = childProps[trigger]; - const valueProps = mergedGetValueProps(value); + const valueProps = name !== undefined ? mergedGetValueProps(value) : {}; // warning when prop value is function if (process.env.NODE_ENV !== 'production' && valueProps) { diff --git a/tests/index.test.tsx b/tests/index.test.tsx index f26bff6c..1968f36c 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -412,6 +412,27 @@ describe('Form.Basic', () => { expect(container.querySelector('.anything')).toBeTruthy(); }); + it('getValueProps should not be executed when name does not exist', async () => { + const getValueProps1 = jest.fn(); + const getValueProps2 = jest.fn(); + + render( +
+
+ + + + + {() => } + +
+
, + ); + + expect(getValueProps1).not.toHaveBeenCalled(); + expect(getValueProps2).not.toHaveBeenCalled(); + }); + describe('shouldUpdate', () => { it('work', async () => { let isAllTouched: boolean;