1

我正在使用 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" />
        );
    }

    ...

}
  1. 有没有办法仍然调用method()

  2. 有什么方法可以访问包装的组件吗?

4

0 回答 0