|
@ -21,6 +21,21 @@ type RenderChildren = (form: FormInstance) => React.ReactNode; |
|
|
type RcFieldProps = Omit<FieldProps, 'children'>; |
|
|
type RcFieldProps = Omit<FieldProps, 'children'>; |
|
|
type ChildrenType = React.ReactElement | RenderChildren | React.ReactElement[] | null; |
|
|
type ChildrenType = React.ReactElement | RenderChildren | React.ReactElement[] | null; |
|
|
|
|
|
|
|
|
|
|
|
interface MemoInputProps { |
|
|
|
|
|
value: any; |
|
|
|
|
|
update: number; |
|
|
|
|
|
children: any; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const MemoInput = React.memo<MemoInputProps>( |
|
|
|
|
|
({ children }) => { |
|
|
|
|
|
return children; |
|
|
|
|
|
}, |
|
|
|
|
|
(prev, next) => { |
|
|
|
|
|
return prev.value === next.value && prev.update === next.update; |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
export interface FormItemProps |
|
|
export interface FormItemProps |
|
|
extends FormItemLabelProps, |
|
|
extends FormItemLabelProps, |
|
|
FormItemInputProps, |
|
|
FormItemInputProps, |
|
@ -216,6 +231,10 @@ function FormItem(props: FormItemProps): React.ReactElement { |
|
|
return renderLayout(children); |
|
|
return renderLayout(children); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Record for real component render
|
|
|
|
|
|
const updateRef = React.useRef(0); |
|
|
|
|
|
updateRef.current += 1; |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Field |
|
|
<Field |
|
|
{...props} |
|
|
{...props} |
|
@ -296,7 +315,14 @@ function FormItem(props: FormItemProps): React.ReactElement { |
|
|
}; |
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
childNode = React.cloneElement(children, childProps); |
|
|
childNode = ( |
|
|
|
|
|
<MemoInput |
|
|
|
|
|
value={mergedControl[props.valuePropName || 'value']} |
|
|
|
|
|
update={updateRef.current} |
|
|
|
|
|
> |
|
|
|
|
|
{React.cloneElement(children, childProps)} |
|
|
|
|
|
</MemoInput> |
|
|
|
|
|
); |
|
|
} else if (isRenderProps && shouldUpdate && !hasName) { |
|
|
} else if (isRenderProps && shouldUpdate && !hasName) { |
|
|
childNode = (children as RenderChildren)(context); |
|
|
childNode = (children as RenderChildren)(context); |
|
|
} else { |
|
|
} else { |
|
|