此代码抛出“无法找到名称'ComposedComponent'”。我不明白为什么会发生这种情况。只想创建简单的HOC。
import * as React from 'react';
import { StatelessComponent, Component } from 'react';
import { connect } from 'react-redux';
interface Props {
isAuthenticated: boolean;
}
const AuthComponent = (ComposedComponent: React.ComponentType<Props>) => {
class Authentication extends Component<Props> {
componentWillMount() {
if (!this.props.isAuthenticated) {
this.context.router.push('/');
}
}
componentWillUpdate(nextProps: Props) {
if (!nextProps.isAuthenticated) {
this.context.router.push('/');
}
}
render() {
return <ComposedComponent {...this.props } />;
}
}
};
答案 0 :(得分:0)
文件扩展名应为.tsx
,而不是.ts