我使用Alt.js的connectToStores来访问组件内的存储状态,但是当我尝试从另一个组件(使用ref)调用该组件的方法时,该方法似乎由于包装器组件而丢失(给出未定义的方法)。
comp_a.js
class CompA extends React.Component {
...
static getStores() { ... }
static getPropsFromStores() { ... }
...
method() {
}
...
}
export default connectToStores(CompA);
comp_b.js
class CompB extends React.Component {
...
test() {
// Causes error because "method()" is lost during connectToStores export
// It seems that connectToStores doesn't inherit the base component, instead it wraps the component with another component.
this.refs.other.method();
}
...
render() {
return (
<CompA ref="other" />
);
}
...
}
有没有办法仍然可以调用方法()?
有没有办法访问包装组件?