如何访问BaseComponent的ref或任何级别的组件?

时间:2016-09-09 19:33:02

标签: reactjs recompose

原始问题:https://github.com/acdlite/recompose/issues/232

如何访问BaseComponent的参考或任何级别的组件?

代码:

class BaseComponent {
    doSth(){...}
}
const Component compose(...some)(BaseComponent);

class App {
    componentDidMount() {
        // undefined(doSth) is not a function
        this.refs.component.doSth();
    }
    render() {
        <Component ref="component" />
   }
}

1 个答案:

答案 0 :(得分:3)

您可以使用hoistStatic

import Ember from 'ember';
export default Ember.Controller.extend({

    actions: {
        save() {
            this.store.createRecord('duel', {
                fighter1: scope.get("fighter1"),
                fighter2: scope.("fighter2"),
            });
        }
    }
});

你可以找到一个真实的例子in the test