ReactJS不能使用组合组件

时间:2016-04-12 07:19:44

标签: javascript reactjs

这是我的超级简单增强器:

'use strict';

import React from 'react';
import BaseComponent from '../composits/Base.jsx';

@BaseComponent
class Home extends React.Component {
    static displayeName = 'Home';

    constructor(props) {
        super(props);
    }

    render() {
        console.log(this.updateState)

        return (
            <div>Hi</div>
        )
    }
}

export default Home

我正在增强我的组件如下:

console.log(this.updateState)

但这不起作用! nullHome。我做错了什么?

修改

也许我在这里遗漏了一些东西。根据我上面的设计,BaseComponent会成为“增强型”组件,还是Home?换句话说,BaseComponent是否可以访问@MappedSuperclass public class SeqIdable implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XyzIdGenerator") @GenericGenerator( name = "XyzIdGenerator", strategy = "com.mycompany.myapp.id.BigIntegerSequenceGenerator", parameters = { @Parameter(name = "sequence", value = "xyz_id_sequence") }) public BigInteger getId() { return id; } } 种方法/州/道具,反之亦然?

1 个答案:

答案 0 :(得分:0)

给它起个名字

function baseComponent(ComposedComponent) {
    return class BaseComponent extends React.Component {
        // ommited
    }
}

 export default baseComponent;

或尝试包装

'use strict';

import React from 'react';
import BaseComponent from '../composits/Base.jsx';

class Home extends React.Component {
    // ommited
}

export default BaseComponent(Home);