Skip to content

Commit 18805db

Browse files
committed
feat: added forwardRef to improve comp. control
1 parent cbc2bc6 commit 18805db

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Field.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,10 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
623623
}
624624
}
625625

626-
function WrapperField<Values = any>({ name, ...restProps }: FieldProps<Values>) {
626+
const WrapperField = React.forwardRef(function WrapperField<Values = any>(
627+
{ name, ...restProps }: FieldProps<Values>,
628+
ref,
629+
) {
627630
const fieldContext = React.useContext(FieldContext);
628631

629632
const namePath = name !== undefined ? getNamePath(name) : undefined;
@@ -644,7 +647,9 @@ function WrapperField<Values = any>({ name, ...restProps }: FieldProps<Values>)
644647
warning(false, '`preserve` should not apply on Form.List fields.');
645648
}
646649

647-
return <Field key={key} name={namePath} {...restProps} fieldContext={fieldContext} />;
648-
}
650+
return <Field ref={ref} key={key} name={namePath} {...restProps} fieldContext={fieldContext} />;
651+
});
652+
653+
WrapperField.displayName = 'Field';
649654

650655
export default WrapperField;

0 commit comments

Comments
 (0)