我正在尝试键入一个HOC,它为传递的Component添加一个prop,如下所示:
// @flow
import React, { Component } from 'react';
import type { ComponentType } from 'react';
type Props = {
x: string,
}
const withReferral = <PassedProps: {}>(
WrappedComponent: ComponentType<PassedProps>
): ComponentType<$Diff<PassedProps, Props>> => {
class withReferral extends Component<PassedProps> {
render() {
return (<WrappedComponent {...this.props} x={'test'} />);
}
}
return withReferral;
};
export default withReferral;
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:"无法返回withReferral,因为withReferral [1]的静态中缺少可调用签名,但存在于React.StatelessFunctionalComponent [2]中."
用[1]引用return withReferral和[2]引用React定义:React$StatelessFunctionalComponent<Props>
谁有任何帮助?