Skip to content

Commit

Permalink
chore: Form.Item renderProps define
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Mar 5, 2020
1 parent 5bb8f58 commit 2ea9d47
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import { toArray, getFieldId } from './util';
const ValidateStatuses = tuple('success', 'warning', 'error', 'validating', '');
export type ValidateStatus = typeof ValidateStatuses[number];

type RenderChildren = (form: FormInstance) => React.ReactElement | null;
type RenderChildren = (form: FormInstance) => React.ReactNode;
type RcFieldProps = Omit<FieldProps, 'children'>;
type ChildrenType = React.ReactElement | RenderChildren | React.ReactElement[] | null;
type ChildrenNodeType = Exclude<ChildrenType, RenderChildren>;

export interface FormItemProps
extends FormItemLabelProps,
Expand Down Expand Up @@ -117,7 +116,7 @@ function FormItem(props: FormItemProps): React.ReactElement {
};

function renderLayout(
baseChildren: ChildrenNodeType,
baseChildren: React.ReactNode,
fieldId?: string,
meta?: Meta,
isRequired?: boolean,
Expand Down Expand Up @@ -214,7 +213,7 @@ function FormItem(props: FormItemProps): React.ReactElement {
const isRenderProps = typeof children === 'function';

if (!hasName && !isRenderProps && !dependencies) {
return renderLayout(children as ChildrenNodeType);
return renderLayout(children);
}

return (
Expand Down Expand Up @@ -263,7 +262,7 @@ function FormItem(props: FormItemProps): React.ReactElement {
id: fieldId,
};

let childNode: ChildrenNodeType = null;
let childNode: React.ReactNode = null;
if (Array.isArray(children) && hasName) {
warning(false, 'Form.Item', '`children` is array of render props cannot have `name`.');
childNode = children;
Expand Down

0 comments on commit 2ea9d47

Please sign in to comment.