1

I'm using Alt.js's connectToStores to access store state inside a component, but when I try to call this component's method from aother component (using a ref), the method seems to be lost because of a wrapper component (gives undefined method).

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. Is there any way to still call method() ?

  2. Is there any way to access the wrapped component?

WoLfulus
  • 1,948
  • 1
  • 14
  • 21
  • @JoshDavidMiller I thought about that too, but its how I managed to get it working without creating a whole new flux/store just for this. Its basically 2 components, 1 is a button that collapses/expands the other. When pressing the button, the other component is called hide()/show() methods. How can I make this work better (making one component inside the other is not an option) – WoLfulus Jan 07 '16 at 05:46
  • @JoshDavidMiller I moved the logic to flux. Works fine and went better than expected. – WoLfulus Jan 07 '16 at 06:03
  • A flux store is good way to go, though there are others too. Glad you got it working! – Josh David Miller Jan 07 '16 at 07:16

0 Answers0