我遇到了一个问题,我可以将一个类或一个功能组件传递到我的 HOC 中。在 HOC 中,我需要访问正在传入的组件上的静态属性(PAGE)。这里的问题是,FLOW 给了我一个错误,说它找不到正在传递给 HOC 的 PAGE 上的静态属性:
Error:(50, 21) Flow: property getInitialProps. Property not found in statics of React$Component
.
该错误来自以下代码中的这一行:
const pageProps =
(await Page.getInitialProps) && (await Page.getInitialProps(ctx))
任何帮助将不胜感激 - 我的全部内容:
type DefaultProps = {
getInitialProps: (ctx:any) => any
}
type FunctionComponent<P> = (props: P) => ?React.Element<*>;
type ClassComponent<D, P, S> = Class<React.Component<D, P, S>>;
type Component<D, P> = FunctionComponent<P> | ClassComponent<D, P, any>;
export default <D: DefaultProps, P: {}, S: {}> (Page: Component<D, P>, title: string = '') => {
class standardLayout extends React.Component {
static async getInitialProps (ctx) {
// Flow can't read getInitialProps
const pageProps = Page.getInitialProps ? (await Page.getInitialProps(ctx)) : await Page.getInitialProps
return {
...pageProps,
currentUrl: ctx.pathname
}
}
render () {
return (
<div>
<Page {...this.props} />
</div>
)
}
}
return connect()(standardLayout)
}