【发布时间】:2021-02-16 07:13:20
【问题描述】:
我遇到了将FormWithRedirect定义为FC(FunctionComponent)的这部分代码:
declare const FormWithRedirect: FC<FormWithRedirectProps>;
export declare type FormWithRedirectProps = FormWithRedirectOwnProps & Omit<FormProps, 'onSubmit' | 'active'>;
export interface FormWithRedirectOwnProps {
defaultValue?: any;
record?: Record;
redirect?: RedirectionSideEffect;
render: (props: Omit<FormViewProps, 'render' | 'setRedirect'>) => React.ReactElement<any, any>;
...
}
下面是它的使用方法:
const SimpleForm: FC<SimpleFormProps> = (props) => (
<FormWithRedirect {...props} render={(formProps) => <SimpleFormView {...formProps} />} />
);
考虑FC的定义如下:
type FC<P = {}> = FunctionComponent<P>;
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement | null;
propTypes?: WeakValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
displayName?: string;
}
我想在使用它之前应该分配给FormWithRedirect(类似于FormWithRedirect = (props) => {....}),但是在上面的代码中没有分配,也没有分配函数。它是如何工作的?
【问题讨论】:
-
试图解释如下:
标签: reactjs typescript