Getting a reference to the class instance of a component

For my scenario I used a singleton (static variable)

export let instance = null;

class SearchDialogue extends React.Component {
    constructor(props) {
        super(props);

        instance = this;
    }
}

then when you need to reference it you can run

import {instance as searchDialogueInstance} from './SearchDialogue'

console.log(searchDialogueInstance.someFooBar);

Note

Keep in mind that this only works WELL if you're leveraging the singleton design pattern. If you are not then you could turn the static var into an array and on push new instances into the array. Careful as this could get you into trouble if you are not already familiar with potential memory pitfalls.

SearchDialogue.instances.push(this);

You have a few options:

(1) Use the return value from ReactDOM.render:

var element = ReactDOM.render(<MyComponent />, myDomElementContainer);

(2) Use React.createElement:

var element = React.createElement(MyComponent);
ReactDOM.render(element);

(3) Use refs:

var element;
ReactDOM.render(<MyComponent ref={el => element = el } />, myDomElementContainer);

The instance will be assigned to element when the instance of MyComponent has been rendered.