在TypeScript

时间:2018-03-19 19:43:31

标签: reactjs typescript

此代码抛出“无法找到名称'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 } />;
        }
    }
};

1 个答案:

答案 0 :(得分:0)

文件扩展名应为.tsx,而不是.ts